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>
using namespace std;
#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string s;
cin >> s;
map<vector<int>, int> cnt;
vector<int> occ(3), null = {0, 0, 0};
int ans = 0;
for (int i = 0; i < n; i++) {
if (s[i] == 'J') occ[0]++;
if (s[i] == 'O') occ[1]++;
if (s[i] == 'I') occ[2]++;
int mn = occ[0];
for (int i = 1; i < 3; i++) mn = min(mn, occ[i]);
for (int i = 0; i < 3; i++) occ[i] -= mn;
if (cnt[occ] || occ == null) ans = max(ans, i - cnt[occ]);
else cnt[occ] = i;
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |