#include <bits/stdc++.h>
#define pii pair <int, int>
using namespace std;
const int maxN = 2e5 + 5;
int n;
int d[2];
signed main () {
ios_base :: sync_with_stdio (0);
cin.tie (0);
cin >> n;
map <pii, int> mp;
int res = 0;
mp[{0, 0}] = 1;
for (int i = 1; i <= n; i ++) {
char cc;
cin >> cc;
if (cc == 'J') {
d[0] ++;
d[1] ++;
}
else if (cc == 'O') {
d[0] --;
}
else {
d[1] --;
}
if (mp.find ({d[0], d[1]}) != mp.end ()) {
res = max (res, i - mp[{d[0], d[1]}]);
}
else {
mp[{d[0], d[1]}] = i;
}
}
cout << res;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |