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 <iostream>
#include <map>
using namespace std;
const int N = 2e5+5;
const long long mpI = 1000000007, mpO = 100000009, mpJ = -(mpI+mpO);
int n, ans = 0;
string s;
long long pref[N], a[N];
map<long long,int> check;
int main()
{
cin >> n >> s;
for (int i = 0; i < n; i++)
{
if (s[i] == 'I') a[i+1] = mpI;
else if (s[i] == 'O') a[i+1] = mpO;
else a[i+1] = mpJ;
}
for (int i = 1; i <= n; i++)
{
pref[i] = pref[i-1] + a[i];
if (check[pref[i]])
{
ans = max(ans,i-check[pref[i]]);
}
else
check[pref[i]] = i;
}
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... |