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 <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 (stderr)
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]];
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |