よじろめ覚書

私の理解度重視のソースコードです。

ABC098B - Cut and Count

問題:B - Cut and Count

#include <iostream>
#include <string>
using namespace std;

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)

bool isMatch(string str, int s, int g, char c) {
    FOR(i, s, g) {
        if (str[i] == c) {
            return true;
        }
    }
    
    return false;
}

int main(void){
    int n, cnt, ans = 0;
    string s;
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    cin >> s;
    REP(i, n) {
        cnt = 0;
        for (char c = 'a'; c <= 'z'; ++c) {
            if (isMatch(s, 0, i, c) && isMatch(s, i, n, c)) {
                cnt++;
            }
        }
        
        ans = max(ans, cnt);
    }
    
    cout << ans << "\n";
    return 0;
}