#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(4e18) + ll(2e15);
const double EPS = 1e-9;
static int LamyIsCute = []() {
EmiliaMyWife
return 48763;
}();
signed main() {
int n, k;
string s;
cin >> n >> k >> s;
vector<vector<int>> cnt(n + 1, vector<int>(3));
const string joi = "JOI";
for(int i = 0; i < n; i++) {
for(int j = 0; j < 3; j++) {
cnt[i + 1][j] = cnt[i][j] + (s[i] == joi[j]);
}
}
int ans = INF;
for(int i = 1; i <= n; i++) {
int cur = i;
bool ok = 1;
for(int j = 0; j < 3; j++) {
if(cnt[n][j] - cnt[cur - 1][j] < k) {
ok = 0;
break;
}
int l = i, r = n;
while(l < r) {
int m = l + r >> 1;
if(cnt[m][j] - cnt[cur - 1][j] < k)
l = m + 1;
else
r = m;
}
cur = l;
}
if(ok)
ans = min(ans, cur - i + 1 - k * 3);
}
if(ans == INF)
cout << "-1\n";
else
cout << ans << '\n';
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:41:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
41 | int m = l + r >> 1;
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
1 ms |
436 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
428 KB |
Output is correct |
30 |
Correct |
1 ms |
416 KB |
Output is correct |
31 |
Correct |
1 ms |
300 KB |
Output is correct |
32 |
Correct |
2 ms |
428 KB |
Output is correct |
33 |
Correct |
1 ms |
436 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
312 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
292 KB |
Output is correct |
15 |
Correct |
1 ms |
436 KB |
Output is correct |
16 |
Correct |
1 ms |
460 KB |
Output is correct |
17 |
Correct |
1 ms |
440 KB |
Output is correct |
18 |
Correct |
1 ms |
312 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
440 KB |
Output is correct |
25 |
Correct |
1 ms |
436 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
428 KB |
Output is correct |
30 |
Correct |
1 ms |
416 KB |
Output is correct |
31 |
Correct |
1 ms |
300 KB |
Output is correct |
32 |
Correct |
2 ms |
428 KB |
Output is correct |
33 |
Correct |
1 ms |
436 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
33 ms |
10828 KB |
Output is correct |
37 |
Correct |
34 ms |
11588 KB |
Output is correct |
38 |
Correct |
36 ms |
11644 KB |
Output is correct |
39 |
Correct |
49 ms |
11480 KB |
Output is correct |
40 |
Correct |
33 ms |
11664 KB |
Output is correct |
41 |
Correct |
41 ms |
11608 KB |
Output is correct |
42 |
Correct |
48 ms |
11660 KB |
Output is correct |
43 |
Correct |
15 ms |
7272 KB |
Output is correct |
44 |
Correct |
21 ms |
9048 KB |
Output is correct |
45 |
Correct |
26 ms |
11660 KB |
Output is correct |
46 |
Correct |
38 ms |
11600 KB |
Output is correct |
47 |
Correct |
25 ms |
11656 KB |
Output is correct |
48 |
Correct |
27 ms |
11656 KB |
Output is correct |
49 |
Correct |
16 ms |
7860 KB |
Output is correct |
50 |
Correct |
25 ms |
11576 KB |
Output is correct |
51 |
Correct |
26 ms |
11596 KB |
Output is correct |
52 |
Correct |
14 ms |
11224 KB |
Output is correct |
53 |
Correct |
18 ms |
11612 KB |
Output is correct |
54 |
Correct |
32 ms |
11608 KB |
Output is correct |
55 |
Correct |
16 ms |
11560 KB |
Output is correct |
56 |
Correct |
20 ms |
11600 KB |
Output is correct |