#include<bits/stdc++.h>
#define god dimasi5eks
#pragma GCC optimize("O3")
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mod 1000000007
#define dancila 3.14159265359
#define eps 1e-9
using namespace std;
typedef long long ll;
int add(int a, int b)
{
ll x = a+b;
if(x >= mod)
x -= mod;
if(x < 0)
x += mod;
return x;
}
ll mul(ll a, ll b)
{
return (a*b) % mod;
}
ll pw(ll a, ll b)
{
ll ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
map<pair<int, pair<int, int> >, int> mp;
int n;
string s;
int v[5];
int ans;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
cin >> s;
mp[{0, {0, 0}}] = -1;
for(int i = 0; i < n; ++i)
{
if(s[i] == 'J')
++v[1];
if(s[i] == 'O')
++v[2];
if(s[i] == 'I')
++v[3];
int mn = min(v[1], min(v[2], v[3]));
if(mp.find({v[1] - mn, {v[2] - mn, v[3] - mn}}) != mp.end())
ans = max(ans, i - mp[{v[1] - mn, {v[2] - mn, v[3] - mn}}]);
else
mp[{v[1] - mn, {v[2] - mn, v[3] - mn}}] = i;
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
380 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
296 KB |
Output is correct |
7 |
Correct |
3 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
3 ms |
380 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
9 ms |
1016 KB |
Output is correct |
3 |
Correct |
15 ms |
1528 KB |
Output is correct |
4 |
Correct |
26 ms |
2268 KB |
Output is correct |
5 |
Correct |
42 ms |
3460 KB |
Output is correct |
6 |
Correct |
48 ms |
3632 KB |
Output is correct |
7 |
Correct |
51 ms |
4100 KB |
Output is correct |
8 |
Correct |
53 ms |
3592 KB |
Output is correct |
9 |
Correct |
52 ms |
3844 KB |
Output is correct |
10 |
Correct |
56 ms |
3716 KB |
Output is correct |
11 |
Correct |
43 ms |
5252 KB |
Output is correct |
12 |
Correct |
40 ms |
2436 KB |
Output is correct |
13 |
Correct |
28 ms |
1672 KB |
Output is correct |
14 |
Correct |
46 ms |
6276 KB |
Output is correct |
15 |
Correct |
25 ms |
1412 KB |
Output is correct |