#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n, k;
string s;
cin >> n >> k >> s;
string target = string(k, 'J') + string(k, 'O') + string(k, 'I');
ll ans = LLONG_MAX;
for (ll j = 0; j < n; ++j) {
ll ptr = 0;
ll mn = LLONG_MAX, mx = LLONG_MIN;
for (ll i = j; i < n; ++i) {
if (s[i] == target[ptr]) {
mn = min(mn, i);
mx = max(mx, i);
ptr++;
}
}
if (ptr == target.length()) {
ans = min(ans, mx - mn + 1 - 3 * k);
}
}
if (ans == LLONG_MAX) {
cout << "-1\n";
} else {
cout << ans << "\n";
}
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if (ptr == target.length()) {
| ~~~~^~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
464 KB |
Output is correct |
21 |
Correct |
6 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
7 ms |
348 KB |
Output is correct |
25 |
Correct |
7 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
460 KB |
Output is correct |
27 |
Correct |
7 ms |
464 KB |
Output is correct |
28 |
Correct |
7 ms |
348 KB |
Output is correct |
29 |
Correct |
7 ms |
460 KB |
Output is correct |
30 |
Correct |
7 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
7 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
348 KB |
Output is correct |
34 |
Correct |
6 ms |
348 KB |
Output is correct |
35 |
Correct |
5 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
4 ms |
348 KB |
Output is correct |
16 |
Correct |
5 ms |
348 KB |
Output is correct |
17 |
Correct |
5 ms |
348 KB |
Output is correct |
18 |
Correct |
3 ms |
344 KB |
Output is correct |
19 |
Correct |
5 ms |
348 KB |
Output is correct |
20 |
Correct |
5 ms |
464 KB |
Output is correct |
21 |
Correct |
6 ms |
348 KB |
Output is correct |
22 |
Correct |
6 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
7 ms |
348 KB |
Output is correct |
25 |
Correct |
7 ms |
348 KB |
Output is correct |
26 |
Correct |
7 ms |
460 KB |
Output is correct |
27 |
Correct |
7 ms |
464 KB |
Output is correct |
28 |
Correct |
7 ms |
348 KB |
Output is correct |
29 |
Correct |
7 ms |
460 KB |
Output is correct |
30 |
Correct |
7 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
7 ms |
344 KB |
Output is correct |
33 |
Correct |
5 ms |
348 KB |
Output is correct |
34 |
Correct |
6 ms |
348 KB |
Output is correct |
35 |
Correct |
5 ms |
344 KB |
Output is correct |
36 |
Execution timed out |
2047 ms |
860 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |