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;
const int N = 2e5 + 5;
int cnti[N], cntj[N], cnto[N];
map <pair <int, int>, int> m;
string s;
int n;
int main()
{
cin >> n;
cin >> s;
s = "1" + s;
for(int i = 1; i <= n; i++)
{
cnti[i] = cnti[i - 1] + (s[i] == 'I');
cntj[i] = cntj[i - 1] + (s[i] == 'J');
cnto[i] = cnto[i - 1] + (s[i] == 'O');
pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]};
if(m[v] == 0)
m[v] = i;
}
int ans = 0;
for(int i = n; i >= 1; i--)
{
pair <int, int> v = {cntj[i] - cnti[i], cntj[i] - cnto[i]};
int j = m[v];
ans = max(ans, i - 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... |