#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
2 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
2 ms |
492 KB |
Output is correct |
9 |
Correct |
2 ms |
620 KB |
Output is correct |
10 |
Correct |
3 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
620 KB |
Output is correct |
2 |
Correct |
10 ms |
1516 KB |
Output is correct |
3 |
Correct |
18 ms |
2412 KB |
Output is correct |
4 |
Correct |
33 ms |
3948 KB |
Output is correct |
5 |
Correct |
54 ms |
6392 KB |
Output is correct |
6 |
Correct |
66 ms |
6392 KB |
Output is correct |
7 |
Correct |
71 ms |
7416 KB |
Output is correct |
8 |
Correct |
62 ms |
6136 KB |
Output is correct |
9 |
Correct |
67 ms |
6776 KB |
Output is correct |
10 |
Correct |
81 ms |
6264 KB |
Output is correct |
11 |
Correct |
62 ms |
9592 KB |
Output is correct |
12 |
Correct |
46 ms |
3832 KB |
Output is correct |
13 |
Correct |
40 ms |
2424 KB |
Output is correct |
14 |
Correct |
66 ms |
11640 KB |
Output is correct |
15 |
Correct |
25 ms |
1788 KB |
Output is correct |