This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int N;
string S;
int f(char x) {
if(x == 'J') return 0;
if(x == 'O') return 1;
if(x == 'I') return 2;
}
struct node {
int a, b, c;
bool operator <(const node &i) const {
if(a != i.a) return a < i.a;
if(b != i.b) return b < i.b;
if(c != i.c) return c < i.c;
return false;
}
};
int cnt[3];
map<node, int> chk;
int main() {
cin >> N >> S;
int ans = 0;
chk[ {0, 0, 0} ] = -1;
for(int i = 0; i < N; i++) {
cnt[ f(S[i]) ]++;
int mn = min(cnt[0], min(cnt[1], cnt[2]));
if(chk.find({ cnt[0] - mn, cnt[1] - mn, cnt[2] - mn }) != chk.end()) {
ans = max(ans, i - chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ]);
}
else chk[ { cnt[0] - mn, cnt[1] - mn, cnt[2] - mn } ] = i;
}
cout << ans;
}
Compilation message (stderr)
joioji.cpp: In function 'int f(char)':
joioji.cpp:11:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |