| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1287248 | TrieTr | JOIOJI (JOI14_joioji) | C++20 | 32 ms | 6016 KiB |
#include<bits/stdc++.h>
using namespace std;
void local() {
#define taskname ""
if(fopen(taskname".inp", "r")) {
freopen(taskname".inp", "r", stdin);
freopen(taskname".out", "w", stdout);
}
}
#define ll long long
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
template <class X, class Y> bool mini(X& x, Y y) {return x > y ? x = y, true : false;}
template <class X, class Y> bool maxi(X& x, Y y) {return x < y ? x = y, true : false;}
const int N = 1e6 + 5;
int n;
string s;
array<int, 3> state;
map<array<int, 3>, int> mp;
int main() {
fastio; local();
cin >> n >> s; s = '#' + s;
state[0] = state[1] = state[2] = 0;
int res = 0;
for(int i = 1; i <= n; i++) {
if(s[i] == 'J') state[0]--, state[1]++;
if(s[i] == 'O') state[1]--, state[2]++;
if(s[i] == 'I') state[2]--, state[0]++;
if(mp.find(state) != mp.end()) {
maxi(res, i - mp[state]);
}
else mp[state] = i;
}
cout << res;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
