#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
300 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |