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 <iostream>
#include <array>
#include <algorithm>
#include <map>
#define ll long long
using namespace std;
ll n, f;
map <array<ll, 2>, ll> mp;
array <ll, 2> cur;
string S;
int main() {
cin >> n >> S;
mp[cur] = -1;
for (int i=0; i<n; ++i) {
if (S[i] == 'J') --cur[0], --cur[1];
else if (S[i] == 'O') ++cur[0];
else ++cur[1];
if (mp.find(cur) == mp.end()) mp[cur] = i;
else {
f = max(f, i-mp[cur]);
}
}
cout << f << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |