#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <stack>
#include <string>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n, k; cin >> n >> k;
string s; cin >> s;
if(s.find_first_of('J') >= s.find_last_of('I')) {
cout << -1;
return 0;
}
s = s.substr(s.find_first_of('J'), s.find_last_of('I') - s.find_first_of('J') + 1);
n = s.size();
ll mn = 1e10;
for(int i = 0; i < n; i++) {
char c = s[i];
if(c != 'J') continue;
ll ileo = 0, ilej = 1, ilei = 0, usu = 0;
for(int j = i+1; j < n; j++) {
char z = s[j];
if(z == 'O') {
if(ileo < k) {
usu += ilei;
ilei = 0;
ileo++;
} else {
usu++;
}
}
if(z == 'J') {
if(ilej < k) {
usu += ileo;
usu += ilei;
ileo = 0;
ilei = 0;
ilej++;
} else {
usu++;
}
}
if(z == 'I') {
if(ilei + 1 >= k && ilej >= k && ileo >= k) {
ilei++;
break;
} else {
ilei++;
}
}
}
if(ilei >= k && ileo >= k && ilej >= k) {
mn = min(usu, mn);
}
}
cout << (mn <= 2e8 ? mn : -1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
592 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
636 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
504 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
592 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
3 ms |
336 KB |
Output is correct |
25 |
Correct |
3 ms |
336 KB |
Output is correct |
26 |
Correct |
3 ms |
336 KB |
Output is correct |
27 |
Correct |
3 ms |
336 KB |
Output is correct |
28 |
Correct |
3 ms |
468 KB |
Output is correct |
29 |
Correct |
3 ms |
636 KB |
Output is correct |
30 |
Correct |
3 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
3 ms |
336 KB |
Output is correct |
33 |
Correct |
2 ms |
336 KB |
Output is correct |
34 |
Correct |
3 ms |
336 KB |
Output is correct |
35 |
Correct |
3 ms |
468 KB |
Output is correct |
36 |
Correct |
4 ms |
988 KB |
Output is correct |
37 |
Correct |
4 ms |
1244 KB |
Output is correct |
38 |
Correct |
4 ms |
988 KB |
Output is correct |
39 |
Execution timed out |
2037 ms |
1248 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |