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 main(){
ios_base::sync_with_stdio(false);
int n;
cin >> n;
string s;
cin >> s;
int I = 0;
int J = 0;
int O = 0;
typedef pair<int,int> ii;
map<ii,int> m;
for(int i = 0;i < n;i++){
if(s[i] == 'I') I++;
else if(s[i] == 'O') O++;
else J++;
m[ii(O-J,O-I)] = i;
}
I = 0, J = 0, O = 0;
int ans = 0;
for(int i = 0;i < n;i++){
if(m.find(ii(O-J,O-I)) != m.end() && m[ii(O-J,O-I)] > i)
ans = max(ans,m[ii(O-J,O-I)] - i + 1);
if(s[i] == 'I') I++;
else if(s[i] == 'O') O++;
else J++;
}
cout << 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... |