#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define MAX 201010
#define MAXS 20
#define INF 1000000000000000001
#define bb ' '
#define ln '\n'
#define Ln '\n'
int tr[127];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
tr['J'] = 0;
tr['O'] = 1;
tr['I'] = 2;
int N;
cin >> N;
int i;
string s;
cin >> s;
int a[3] = { 0, 0, 0 };
map<pii, int> mp;
mp[pii(0, 0)] = 1;
int ans = 0;
for (i = 1; i <= N; i++) {
int t = tr[s[i - 1]];
a[t]++;
if (mp[pii(a[1] - a[0], a[2] - a[0])]) ans = max(a[0] - mp[pii(a[1] - a[0], a[2] - a[0])] + 1, ans);
else mp[pii(a[1] - a[0], a[2] - a[0])] = a[0] + 1;
}
cout << ans * 3 << Ln;
}
Compilation message
joioji.cpp: In function 'int main()':
joioji.cpp:32:22: warning: array subscript has type 'char' [-Wchar-subscripts]
32 | int t = tr[s[i - 1]];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
316 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
5 ms |
852 KB |
Output is correct |
3 |
Correct |
9 ms |
1356 KB |
Output is correct |
4 |
Correct |
16 ms |
2260 KB |
Output is correct |
5 |
Correct |
27 ms |
3448 KB |
Output is correct |
6 |
Correct |
33 ms |
3552 KB |
Output is correct |
7 |
Correct |
33 ms |
4120 KB |
Output is correct |
8 |
Correct |
31 ms |
3416 KB |
Output is correct |
9 |
Correct |
33 ms |
3776 KB |
Output is correct |
10 |
Correct |
30 ms |
3464 KB |
Output is correct |
11 |
Correct |
29 ms |
5132 KB |
Output is correct |
12 |
Correct |
22 ms |
2280 KB |
Output is correct |
13 |
Correct |
20 ms |
1516 KB |
Output is correct |
14 |
Correct |
29 ms |
6108 KB |
Output is correct |
15 |
Correct |
23 ms |
1232 KB |
Output is correct |