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 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... |