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>
#define int long long
using namespace std;
const int N = 2e5 + 42, INF = 1e18 + 42;
int n, nb[3], val[N];
map<pair<int, int>, int> first;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 0; i < n; i++) {
char c; cin >> c;
if(c == 'O')
val[i] = 1;
else if(c == 'I')
val[i] = 2;
}
int maxi = 0;
first[{0, 0}] = -1;
for(int i = 0; i < n; i++) {
nb[val[i]]++;
if(first.find({nb[1] - nb[0], nb[2] - nb[0]}) == first.end()) {
first[{nb[1] - nb[0], nb[2] - nb[0]}] = i;
} else {
maxi = max(maxi, i - first[{nb[1] - nb[0], nb[2] - nb[0]}]);
}
}
cout << maxi;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |