이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |