#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) x.begin(),x.end()
int const N = 200001;
int n, k, c0[N], c1[N], c2[N], ad[N];
vector<int> g[N];
int main(){
string s;
scanf("%d%d", &n, &k);
cin >> s;
int an = 1e9, f = -1;
for(int i = 0; i<n; ++i){
c0[i] = (s[i] != 'J');
c1[i] = (s[i] != 'O');
c2[i] = (s[i] != 'I');
g[s[i]].push_back(i);
if(i)c0[i] += c0[i-1], c1[i] += c1[i-1], c2[i] += c2[i-1];
}
for(int i = 0; i<g['J'].size()-k+1; ++i){
int l = g['J'][i], r = g['J'][i+k-1];
int rem = r-l+1 - k;
int it = lower_bound(all(g['O']), r)-g['O'].begin();
if(it == g['O'].size() || it+k > g['O'].size())break;
int itr = g['O'][it+k-1];
it = g['O'][it];
rem += (it-r-1)+(itr-it+1-k);
int ii = lower_bound(all(g['I']), itr)-g['I'].begin();
if(ii == g['I'].size() || ii+k > g['I'].size())break;
int iir = g['I'][ii+k-1];
ii = g['I'][ii];
rem += (ii-itr-1)+(iir-ii+1-k);
an = min(an, rem);
f = 1;
}
printf("%d\n", ~f? an: -1);
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:12: warning: array subscript has type 'char' [-Wchar-subscripts]
g[s[i]].push_back(i);
^
ho_t2.cpp:22:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i<g['J'].size()-k+1; ++i){
~^~~~~~~~~~~~~~~~~~
ho_t2.cpp:26:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it == g['O'].size() || it+k > g['O'].size())break;
~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:26:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it == g['O'].size() || it+k > g['O'].size())break;
~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:31:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ii == g['I'].size() || ii+k > g['I'].size())break;
~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:31:40: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ii == g['I'].size() || ii+k > g['I'].size())break;
~~~~~^~~~~~~~~~~~~~~
ho_t2.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &k);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
3 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
5120 KB |
Output is correct |
18 |
Correct |
5 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
3 ms |
5120 KB |
Output is correct |
21 |
Correct |
3 ms |
5120 KB |
Output is correct |
22 |
Correct |
3 ms |
5120 KB |
Output is correct |
23 |
Correct |
3 ms |
5120 KB |
Output is correct |
24 |
Correct |
3 ms |
5120 KB |
Output is correct |
25 |
Correct |
3 ms |
5120 KB |
Output is correct |
26 |
Correct |
5 ms |
5120 KB |
Output is correct |
27 |
Correct |
3 ms |
5120 KB |
Output is correct |
28 |
Correct |
4 ms |
5120 KB |
Output is correct |
29 |
Correct |
3 ms |
5120 KB |
Output is correct |
30 |
Correct |
3 ms |
5120 KB |
Output is correct |
31 |
Correct |
3 ms |
5120 KB |
Output is correct |
32 |
Correct |
3 ms |
5120 KB |
Output is correct |
33 |
Correct |
3 ms |
5120 KB |
Output is correct |
34 |
Correct |
3 ms |
5120 KB |
Output is correct |
35 |
Correct |
3 ms |
5120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
4992 KB |
Output is correct |
2 |
Correct |
3 ms |
4992 KB |
Output is correct |
3 |
Correct |
3 ms |
4992 KB |
Output is correct |
4 |
Correct |
3 ms |
4992 KB |
Output is correct |
5 |
Correct |
3 ms |
4992 KB |
Output is correct |
6 |
Correct |
3 ms |
4992 KB |
Output is correct |
7 |
Correct |
3 ms |
4992 KB |
Output is correct |
8 |
Correct |
3 ms |
4992 KB |
Output is correct |
9 |
Correct |
4 ms |
5120 KB |
Output is correct |
10 |
Correct |
3 ms |
4992 KB |
Output is correct |
11 |
Correct |
3 ms |
4992 KB |
Output is correct |
12 |
Correct |
3 ms |
4992 KB |
Output is correct |
13 |
Correct |
3 ms |
4992 KB |
Output is correct |
14 |
Correct |
3 ms |
4992 KB |
Output is correct |
15 |
Correct |
3 ms |
5120 KB |
Output is correct |
16 |
Correct |
4 ms |
5120 KB |
Output is correct |
17 |
Correct |
5 ms |
5120 KB |
Output is correct |
18 |
Correct |
5 ms |
5120 KB |
Output is correct |
19 |
Correct |
4 ms |
5120 KB |
Output is correct |
20 |
Correct |
3 ms |
5120 KB |
Output is correct |
21 |
Correct |
3 ms |
5120 KB |
Output is correct |
22 |
Correct |
3 ms |
5120 KB |
Output is correct |
23 |
Correct |
3 ms |
5120 KB |
Output is correct |
24 |
Correct |
3 ms |
5120 KB |
Output is correct |
25 |
Correct |
3 ms |
5120 KB |
Output is correct |
26 |
Correct |
5 ms |
5120 KB |
Output is correct |
27 |
Correct |
3 ms |
5120 KB |
Output is correct |
28 |
Correct |
4 ms |
5120 KB |
Output is correct |
29 |
Correct |
3 ms |
5120 KB |
Output is correct |
30 |
Correct |
3 ms |
5120 KB |
Output is correct |
31 |
Correct |
3 ms |
5120 KB |
Output is correct |
32 |
Correct |
3 ms |
5120 KB |
Output is correct |
33 |
Correct |
3 ms |
5120 KB |
Output is correct |
34 |
Correct |
3 ms |
5120 KB |
Output is correct |
35 |
Correct |
3 ms |
5120 KB |
Output is correct |
36 |
Correct |
22 ms |
8456 KB |
Output is correct |
37 |
Correct |
23 ms |
8908 KB |
Output is correct |
38 |
Correct |
24 ms |
9076 KB |
Output is correct |
39 |
Correct |
23 ms |
8968 KB |
Output is correct |
40 |
Correct |
19 ms |
9056 KB |
Output is correct |
41 |
Correct |
23 ms |
9072 KB |
Output is correct |
42 |
Correct |
26 ms |
8964 KB |
Output is correct |
43 |
Correct |
12 ms |
7432 KB |
Output is correct |
44 |
Correct |
14 ms |
8056 KB |
Output is correct |
45 |
Correct |
17 ms |
9092 KB |
Output is correct |
46 |
Correct |
18 ms |
8956 KB |
Output is correct |
47 |
Correct |
18 ms |
9080 KB |
Output is correct |
48 |
Correct |
17 ms |
9088 KB |
Output is correct |
49 |
Correct |
12 ms |
7560 KB |
Output is correct |
50 |
Correct |
17 ms |
8960 KB |
Output is correct |
51 |
Correct |
17 ms |
8960 KB |
Output is correct |
52 |
Correct |
16 ms |
8524 KB |
Output is correct |
53 |
Correct |
17 ms |
8908 KB |
Output is correct |
54 |
Correct |
20 ms |
9224 KB |
Output is correct |
55 |
Correct |
18 ms |
9096 KB |
Output is correct |
56 |
Correct |
17 ms |
9096 KB |
Output is correct |