#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define int long long
using namespace std;
#ifdef LOCAL
#define WOSAOJI freopen("in.txt", "r", stdin);
#else
#define WOSAOJI ios_base::sync_with_stdio(0), cin.tie(0);
#endif
#define chmax(a, b) (a) = (a) > (b) ? (a) : (b)
#define chmin(a, b) (a) = (a) < (b) ? (a) : (b)
int n, k;
string s;
int calc(int i, vector<vector<int>> &cnt) {
int here = i;
i--;
i = lower_bound(all(cnt[0]), cnt[0][i] + k) - cnt[0].begin();
if (i > n) return 1 << 30;
i = lower_bound(all(cnt[1]), cnt[1][i] + k) - cnt[1].begin();
if (i > n) return 1 << 30;
i = lower_bound(all(cnt[2]), cnt[2][i] + k) - cnt[2].begin();
if (i > n) return 1 << 30;
return i - here + 1;
}
signed main() {
WOSAOJI
cin >> n >> k;
cin >> s;
vector<vector<int>> cnt(3, vector<int>(n + 1, 0));
s = " " + s;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 3; j++) cnt[j][i] = cnt[j][i - 1];
if (s[i] == 'J') cnt[0][i]++;
if (s[i] == 'O') cnt[1][i]++;
if (s[i] == 'I') cnt[2][i]++;
}
int ans = 1 << 30;
for (int i = 1; i <= n; i++) {
if (s[i] == 'J') chmin(ans, calc(i, cnt));
}
if (ans == 1 << 30) ans = k * 3 - 1;
cout << ans - k * 3 << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
1 ms |
320 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
320 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
0 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
316 KB |
Output is correct |
14 |
Correct |
0 ms |
320 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
316 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
320 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
320 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
18 ms |
6624 KB |
Output is correct |
37 |
Correct |
17 ms |
7008 KB |
Output is correct |
38 |
Correct |
18 ms |
7124 KB |
Output is correct |
39 |
Correct |
17 ms |
7008 KB |
Output is correct |
40 |
Correct |
14 ms |
7000 KB |
Output is correct |
41 |
Correct |
16 ms |
7000 KB |
Output is correct |
42 |
Correct |
21 ms |
7028 KB |
Output is correct |
43 |
Correct |
9 ms |
4560 KB |
Output is correct |
44 |
Correct |
11 ms |
5592 KB |
Output is correct |
45 |
Correct |
13 ms |
7008 KB |
Output is correct |
46 |
Correct |
13 ms |
7004 KB |
Output is correct |
47 |
Correct |
13 ms |
7116 KB |
Output is correct |
48 |
Correct |
13 ms |
7112 KB |
Output is correct |
49 |
Correct |
8 ms |
4832 KB |
Output is correct |
50 |
Correct |
12 ms |
7008 KB |
Output is correct |
51 |
Correct |
14 ms |
7008 KB |
Output is correct |
52 |
Correct |
10 ms |
6752 KB |
Output is correct |
53 |
Correct |
10 ms |
7008 KB |
Output is correct |
54 |
Correct |
11 ms |
7008 KB |
Output is correct |
55 |
Correct |
8 ms |
6996 KB |
Output is correct |
56 |
Correct |
7 ms |
7008 KB |
Output is correct |