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;
#define int long long
signed main() {
ios::sync_with_stdio(0); cin.tie(0);
int n;
cin >> n;
string s;
cin >> s;
int ans = 0, J = 0, O = 0, I = 0;
map<pair<int,int>, int> m;
m[{0, 0}] = -1;
for (int i=0;i<n;i++) {
if (s[i]=='J') J++;
if (s[i]=='O') O++;
if (s[i]=='I') I++;
if (!m.count({O-J, I-J})) m[{O-J, I-J}] = i;
else ans = max(i - m[{O-J, I-J}], ans);
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |