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 <cstdio>
#include <map>
#define PLL pair<ll, ll>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll n;
string s;
ll a, b, ans;
map<PLL, ll> ma1, ma2;
int main()
{
cin>>n>>s;
ma1[make_pair(0, 0)] = ma2[make_pair(0, 0)] = 1;
for(ll i = 0; i < n; i++)
{
if(s[i] == 'J')
{
a++;
}
else if(s[i] == 'O')
{
a--, b++;
}
else
{
b--;
}
if(!ma1.count(make_pair(a, b))) ma1[make_pair(a, b)] = i + 2;
ma2[make_pair(a, b)] = i + 2;
}
for(auto i:ma1)
{
ll t1 = i.F.F;
ll t2 = i.F.S;
ll t3 = i.S;
ans = max(ans, ma2[make_pair(t1, t2)] - t3);
}
printf("%lld\n", ans);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |