이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
int n, k, p[3][200005], ans;
string s, t = "JOI";
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k >> s;
for(int j = 1; j <= n; j++){
for(int i = 0; i < 3; i++) p[i][j] = p[i][j - 1];
for(int i = 0; i < 3; i++)
if(s[j - 1] == t[i]) p[i][j]++;
}
p[0][n + 1] = p[1][n + 1] = p[2][n + 1] = 1e9;
ans = n + 1;
for(int s = 0; s < n; s++){
int x = s, cnt = 0;
for(int i = 0; i < 3; i++){
cnt = p[i][x] + k;
x = lower_bound(p[i], p[i] + n + 2, cnt) - p[i];
if(x == n + 1) break;
}
cout << '\n';
if(x <= n) ans = min(ans, x - s - 3 * k);
}
cout << (ans == n + 1 ? -1 : ans);
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... |