#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define X first
#define Y second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb emplace_back
#define endl "\n"
const ll inf = 1e18;
const int N = 2e5 + 5;
typedef pair<int,int> ii;
int c[N][3];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, k; cin >> n >> k;
string S; cin >> S;
S = "#" + S;
for(int i = 1 ; i <= n ; ++i) {
c[i][0] = c[i - 1][0] + (S[i] == 'J');
c[i][1] = c[i - 1][1] + (S[i] == 'O');
c[i][2] = c[i - 1][2] + (S[i] == 'I');
}
int ans = 1e9 + 7;
for(int i = 1 ; i <= n ; ++i) {
int p = i;
for(int j = 0 ; j < 3 ; ++j) {
int l = p;
int r = n + 1;
while (l < r) {
int m = l + r >> 1;
if (c[m][j] - c[p - 1][j] >= k)
r = m;
else
l = m + 1;
}
p = l;
}
if (p <= n)
ans = min(ans,p + 1 - 3 * k - i);
}
if (ans == 1e9 + 7)
ans = -1;
cout << ans << endl;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:46:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int m = l + r >> 1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
372 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
380 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
376 KB |
Output is correct |
9 |
Correct |
5 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
4 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
380 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
372 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
5 ms |
376 KB |
Output is correct |
25 |
Correct |
6 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
6 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
5 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
26 ms |
2764 KB |
Output is correct |
37 |
Correct |
44 ms |
3004 KB |
Output is correct |
38 |
Correct |
28 ms |
3008 KB |
Output is correct |
39 |
Correct |
34 ms |
3008 KB |
Output is correct |
40 |
Correct |
28 ms |
3008 KB |
Output is correct |
41 |
Correct |
32 ms |
3008 KB |
Output is correct |
42 |
Correct |
76 ms |
3012 KB |
Output is correct |
43 |
Correct |
22 ms |
2168 KB |
Output is correct |
44 |
Correct |
20 ms |
2412 KB |
Output is correct |
45 |
Correct |
24 ms |
3008 KB |
Output is correct |
46 |
Correct |
25 ms |
3012 KB |
Output is correct |
47 |
Correct |
27 ms |
3008 KB |
Output is correct |
48 |
Correct |
32 ms |
3008 KB |
Output is correct |
49 |
Correct |
20 ms |
2176 KB |
Output is correct |
50 |
Correct |
25 ms |
3008 KB |
Output is correct |
51 |
Correct |
32 ms |
3004 KB |
Output is correct |
52 |
Correct |
27 ms |
2888 KB |
Output is correct |
53 |
Correct |
19 ms |
3008 KB |
Output is correct |
54 |
Correct |
20 ms |
3008 KB |
Output is correct |
55 |
Correct |
16 ms |
3004 KB |
Output is correct |
56 |
Correct |
20 ms |
3008 KB |
Output is correct |