#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
using namespace std;
ll n,k,r[200005][3],ans;
string s;
int main(){
ios::sync_with_stdio(false);
cin >> n >> k >> s;
for(int i=0; i<s.size(); i++){
if(i){
r[i][0] = r[i - 1][0];
r[i][1] = r[i - 1][1];
r[i][2] = r[i - 1][2];
}
if(s[i] == 'J')r[i][0]++;
if(s[i] == 'O')r[i][1]++;
if(s[i] == 'I')r[i][2]++;
}
ll ans = -1;
for(int i=0; i<s.size(); i++){
ll mx = 0,st = i;
for(int j=0; j<3; j++){
ll l = st , R = (int)s.size() - 1, mid,ind=-1;
ll val = 0;
if(st)val = r[st - 1][j];
while(R >= l){
mid = (l + R) / 2;
if(r[mid][j] - val >= k){
R = mid - 1;
ind = mid;
}
else {
l = mid + 1;
}
}
if(ind == -1){
mx = -1;
break;
}
st = ind;
mx = max(mx , ind);
}
if(mx == -1)continue;
if(ans == -1)ans = n - 3 * k - i - (n - mx - 1);
ans = min(ans , n - 3 * k - i - (n - mx - 1));
}
cout << ans << '\n';
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
13 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
ho_t2.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0; i<s.size(); i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
416 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
416 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
324 KB |
Output is correct |
24 |
Correct |
1 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
33 ms |
5260 KB |
Output is correct |
37 |
Correct |
36 ms |
5516 KB |
Output is correct |
38 |
Correct |
37 ms |
5516 KB |
Output is correct |
39 |
Correct |
41 ms |
5516 KB |
Output is correct |
40 |
Correct |
29 ms |
5516 KB |
Output is correct |
41 |
Correct |
39 ms |
5516 KB |
Output is correct |
42 |
Correct |
41 ms |
5516 KB |
Output is correct |
43 |
Correct |
17 ms |
3584 KB |
Output is correct |
44 |
Correct |
20 ms |
4364 KB |
Output is correct |
45 |
Correct |
26 ms |
5516 KB |
Output is correct |
46 |
Correct |
25 ms |
5516 KB |
Output is correct |
47 |
Correct |
26 ms |
5516 KB |
Output is correct |
48 |
Correct |
25 ms |
5516 KB |
Output is correct |
49 |
Correct |
16 ms |
3852 KB |
Output is correct |
50 |
Correct |
26 ms |
5516 KB |
Output is correct |
51 |
Correct |
25 ms |
5516 KB |
Output is correct |
52 |
Correct |
13 ms |
5388 KB |
Output is correct |
53 |
Correct |
15 ms |
5516 KB |
Output is correct |
54 |
Correct |
20 ms |
5516 KB |
Output is correct |
55 |
Correct |
15 ms |
5516 KB |
Output is correct |
56 |
Correct |
12 ms |
5516 KB |
Output is correct |