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 <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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |