Submission #18712

#TimeUsernameProblemLanguageResultExecution timeMemory
18712kdh9949JOIOJI (JOI14_joioji)C++98
100 / 100
45 ms6952 KiB
#include <cstdio>
#include <map>
using namespace std;
typedef long long ll;

int n, J, O, I, ans;
ll k;
char str[200010];
map<ll, int> mp;

int main(){
    scanf("%d%s", &n, str + 2);
    J = O = I = n;
    mp[(4ll * n * n) * J + (2ll * n) * O + I] = 1;
    for(int i = 2; i < n + 2; i++){
        str[i] == 'J' ? J++ : str[i] == 'O' ? O++ : I++;
        k = (4ll * n * n) * n + (2ll * n) * (O + (n - J)) + (I + (n - J));
        if(!mp[k]) mp[k] = i;
        else ans = max(ans, i - mp[k]);
    }
    printf("%d", ans);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...