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;
bool ok (int u, string s) {
vector<int> cnt (26);
int p1 = 0, p2 = u*3-1;
for (int i = p1; i <= p2; i++) cnt[s[i]-'A']++;
if (cnt['J'-'A'] == u && cnt['O'-'A'] == u && cnt['I'-'A'] == u) return true;
while (p2+1 < (int) s.size()) {
cnt[s[p1]-'A']--;
p1++;
p2++;
cnt[s[p2]-'A']++;
if (cnt['J'-'A'] == u && cnt['O'-'A'] == u && cnt['I'-'A'] == u) return true;
}
return false;
}
int main () {
int n;
string s;
cin >> n >> s;
int l = 0, r = n/3 + 1;
while (l+1 < r) {
int mid = (l+r)/2;
if (ok(mid, s)) l = mid;
else r = mid;
}
cout << l*3 << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |