#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
set <int> J, O, I;
for(int i = 0; i < n; i++){
switch(s[i]){
case 'J':
J.insert(i);
break;
case 'O':
O.insert(i);
break;
case 'I':
I.insert(i);
break;
}
}
set <int>::iterator it1, it2, it3;
it1 = J.begin();
int mi = 200005;
bool pos;
for(int i = 0; i < J.size() - k + 1; i++){
pos = true;
it2 = it1;
//cout << *it1 << ' ';
for(int j = 0; j < k - 1 && pos; j++){
it2++;
if(it2 == J.end()){
pos = false;
}
}
if(pos == false) continue;
//cout << *it2 << ' ';
it2 = O.upper_bound(*it2);
if(it2 == O.end()){
continue;
}
//cout << *it2 << ' ';
for(int j = 0; j < k - 1 && pos; j++){
it2++;
if(it2 == O.end()){
pos = false;
}
}
if(pos == false) continue;
//cout << *it2 << ' ';
it2 = I.upper_bound(*it2);
if(it2 == I.end()){
continue;
}
//cout << *it2 << ' ';
for(int j = 0; j < k - 1 && pos; j++){
it2++;
if(it2 == I.end()){
pos = false;
}
}
if(pos == false) continue;
//cout << *it2 << '\n';
mi = min(mi, *it2 - *it1 + 1 - (k * 3));
it1++;
}
if(mi == 200005) cout << -1;
else cout << mi;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:28:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i = 0; i < J.size() - k + 1; i++){
~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
248 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
248 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
7 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
9 ms |
504 KB |
Output is correct |
22 |
Correct |
9 ms |
504 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
10 ms |
504 KB |
Output is correct |
25 |
Correct |
11 ms |
504 KB |
Output is correct |
26 |
Correct |
11 ms |
504 KB |
Output is correct |
27 |
Correct |
12 ms |
504 KB |
Output is correct |
28 |
Correct |
10 ms |
504 KB |
Output is correct |
29 |
Correct |
10 ms |
504 KB |
Output is correct |
30 |
Correct |
10 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
9 ms |
504 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
10 ms |
504 KB |
Output is correct |
35 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
4 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
5 ms |
248 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
248 KB |
Output is correct |
15 |
Correct |
6 ms |
504 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
504 KB |
Output is correct |
18 |
Correct |
7 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
504 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
9 ms |
504 KB |
Output is correct |
22 |
Correct |
9 ms |
504 KB |
Output is correct |
23 |
Correct |
6 ms |
376 KB |
Output is correct |
24 |
Correct |
10 ms |
504 KB |
Output is correct |
25 |
Correct |
11 ms |
504 KB |
Output is correct |
26 |
Correct |
11 ms |
504 KB |
Output is correct |
27 |
Correct |
12 ms |
504 KB |
Output is correct |
28 |
Correct |
10 ms |
504 KB |
Output is correct |
29 |
Correct |
10 ms |
504 KB |
Output is correct |
30 |
Correct |
10 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
9 ms |
504 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
10 ms |
504 KB |
Output is correct |
35 |
Correct |
5 ms |
504 KB |
Output is correct |
36 |
Correct |
49 ms |
9220 KB |
Output is correct |
37 |
Correct |
54 ms |
9988 KB |
Output is correct |
38 |
Correct |
53 ms |
9988 KB |
Output is correct |
39 |
Execution timed out |
2095 ms |
9860 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |