#include <bits/stdc++.h>
#define int long long int
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define INF 1e13
using namespace std;
int N, K, ans = INF;
string S;
vector<int> js, os, is;
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> N >> K >> S;
for (int i = 0; i < N; i++) {
if (S[i] == 'J') js.pb(i);
if (S[i] == 'O') os.pb(i);
if (S[i] == 'I') is.pb(i);
}
if (js.size() < K or os.size() < K or is.size() < K) {
cout << -1 << "\n";
return 0;
}
for (int i = 0; i <= js.size() - K; i++) {
int total = 0;
total += js[i + K - 1] - js[i] + 1 - K;
int curI = js[i + K - 1];
int off = upper_bound(os.begin(), os.end(), curI) - os.begin();
if (off >= os.size() or os.size() - off < K) continue;
total += os[off] - curI - 1;
total += os[off + K - 1] - os[off] + 1 - K;
curI = os[off + K - 1];
int off2 = upper_bound(is.begin(), is.end(), curI) - is.begin();
if (off2 >= is.size() or is.size() - off2 < K) continue;
total += is[off2] - curI - 1;
total += is[off2 + K - 1] - is[off2] + 1 - K;
curI = is[off2 + K - 1];
ans = min(ans, total);
}
cout << (ans == INF ? -1 : ans) << "\n";
return 0;
}
Compilation message
ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:30:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
30 | if (js.size() < K or os.size() < K or is.size() < K) {
| ~~~~~~~~~~^~~
ho_t2.cpp:30:33: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
30 | if (js.size() < K or os.size() < K or is.size() < K) {
| ~~~~~~~~~~^~~
ho_t2.cpp:30:50: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
30 | if (js.size() < K or os.size() < K or is.size() < K) {
| ~~~~~~~~~~^~~
ho_t2.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'long long unsigned int' [-Wsign-compare]
35 | for (int i = 0; i <= js.size() - K; i++) {
| ~~^~~~~~~~~~~~~~~~
ho_t2.cpp:42:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | if (off >= os.size() or os.size() - off < K) continue;
| ~~~~^~~~~~~~~~~~
ho_t2.cpp:42:43: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
42 | if (off >= os.size() or os.size() - off < K) continue;
| ~~~~~~~~~~~~~~~~^~~
ho_t2.cpp:49:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | if (off2 >= is.size() or is.size() - off2 < K) continue;
| ~~~~~^~~~~~~~~~~~
ho_t2.cpp:49:45: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
49 | if (off2 >= is.size() or is.size() - off2 < K) continue;
| ~~~~~~~~~~~~~~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
600 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
600 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
9 ms |
2248 KB |
Output is correct |
37 |
Correct |
9 ms |
2772 KB |
Output is correct |
38 |
Correct |
9 ms |
2868 KB |
Output is correct |
39 |
Correct |
9 ms |
2728 KB |
Output is correct |
40 |
Correct |
7 ms |
2772 KB |
Output is correct |
41 |
Correct |
9 ms |
2772 KB |
Output is correct |
42 |
Correct |
9 ms |
2780 KB |
Output is correct |
43 |
Correct |
4 ms |
1712 KB |
Output is correct |
44 |
Correct |
5 ms |
2004 KB |
Output is correct |
45 |
Correct |
6 ms |
2712 KB |
Output is correct |
46 |
Correct |
6 ms |
2712 KB |
Output is correct |
47 |
Correct |
6 ms |
2772 KB |
Output is correct |
48 |
Correct |
6 ms |
2744 KB |
Output is correct |
49 |
Correct |
4 ms |
1748 KB |
Output is correct |
50 |
Correct |
6 ms |
2744 KB |
Output is correct |
51 |
Correct |
6 ms |
2772 KB |
Output is correct |
52 |
Correct |
3 ms |
2368 KB |
Output is correct |
53 |
Correct |
4 ms |
2640 KB |
Output is correct |
54 |
Correct |
4 ms |
3040 KB |
Output is correct |
55 |
Correct |
3 ms |
3092 KB |
Output is correct |
56 |
Correct |
3 ms |
3040 KB |
Output is correct |