# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
244885 | maximath_1 | JJOOII 2 (JOI20_ho_t2) | C++11 | 47 ms | 2960 KiB |
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;
int n, k; string s;
int pref[200005][3];
int main(){
cin >> n >> k;
cin >> s;
for(int i = 0; i < n; i ++){
if(i > 0)
for(int j = 0; j < 3; j ++)
pref[i][j] = pref[i-1][j];
if(s[i] == 'J') pref[i][0] ++;
if(s[i] == 'O') pref[i][1] ++;
if(s[i] == 'I') pref[i][2] ++;
}
int ans = 2e9;
for(int i = 0; i < n; i ++){
int cr = i;
int lf = cr, rg = n, md;
for(; lf < rg;){
md = (lf + rg) / 2;
if(pref[md][0] - (cr > 0 ? pref[cr - 1][0] : 0) >= k) rg = md;
else lf = md + 1;
}
cr = lf;
lf = cr, rg = n, md;
for(; lf < rg;){
md = (lf + rg) / 2;
if(pref[md][1] - (cr > 0 ? pref[cr - 1][1] : 0) >= k) rg = md;
else lf = md + 1;
}
cr = lf;
lf = cr, rg = n, md;
for(; lf < rg;){
md = (lf + rg) / 2;
if(pref[md][2] - (cr > 0 ? pref[cr - 1][2] : 0) >= k) rg = md;
else lf = md + 1;
}
cr = lf;
if(cr == n) continue;
ans = min(ans, cr - i + 1 - 3 * k);
}
if(ans > n) ans = -1;
printf("%d\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |