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;
typedef pair<int,int> pi;
map<pi,vector<int> > m;
int N, curJ = 0, curO = 0, curI = 0;
char x;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> N;
m[pi(0,0)] = vector<int>(1,0);
for (int i = 1; i <= N; ++i){
cin >> x;
if (x == 'J') curJ++;
else if (x == 'O') curO++;
else curI++;
if (m.find(pi(curO-curJ,curI-curO)) == m.end()){
m[pi(curO-curJ,curI-curO)] = vector<int>();
}
m[pi(curO-curJ,curI-curO)].push_back(i);
}
int maxi = 0;
for (auto it : m){
maxi = max(maxi,it.second.back()-it.second[0]);
}
cout << maxi << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |