#include <bits/stdc++.h>
using namespace std;
#define idata vector<int>
int N, K;
string buffer;
idata J, O, I;
void cumul (idata &s) {
for (int i = 1; i < s.size(); i ++)
s[i] += s[i - 1];
}
int bs (idata &u, int v) {
int a = - 1;
int b = u.size();
while (b - a > 1) {
int c = (a + b) >> 1;
if (u[c] >= v) b = c;
else a = c;
}
return b;
}
int getl (idata &v, int u) {
u --; if (u == -1) return 0;
return v[u];
}
int find (int l) {
int j = bs(J, getl(J, l) + K);
if (j == N) return N;
int o = bs(O, getl(O, j) + K);
if (o == N) return N;
int i = bs(I, getl(I, o) + K);
return i;
}
int main () {
cin >> N >> K >> buffer;
J.resize(N);
O.resize(N);
I.resize(N);
for (int i = 0; i < N; i ++) {
if (buffer[i] == 'J') J[i] ++;
if (buffer[i] == 'O') O[i] ++;
if (buffer[i] == 'I') I[i] ++;
}
cumul(J);
cumul(O);
cumul(I);
int res = N + 2;
for (int i = 0; i < N; i ++) {
int n = find(i);
if (n == N) continue ;
res = min(res, n - i);
}
if (res != N + 2) res -= K * 3 - 1;
else res = -1;
cout << res << endl;
}
Compilation message
ho_t2.cpp: In function 'void cumul(std::vector<int>&)':
ho_t2.cpp:14:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for (int i = 1; i < s.size(); i ++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 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 |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
1 ms |
212 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 |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
304 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
2 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
296 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 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 |
296 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
1 ms |
212 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 |
300 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
49 ms |
2916 KB |
Output is correct |
37 |
Correct |
56 ms |
3172 KB |
Output is correct |
38 |
Correct |
55 ms |
3172 KB |
Output is correct |
39 |
Correct |
55 ms |
3040 KB |
Output is correct |
40 |
Correct |
48 ms |
3172 KB |
Output is correct |
41 |
Correct |
48 ms |
3172 KB |
Output is correct |
42 |
Correct |
52 ms |
3172 KB |
Output is correct |
43 |
Correct |
21 ms |
2084 KB |
Output is correct |
44 |
Correct |
29 ms |
2564 KB |
Output is correct |
45 |
Correct |
39 ms |
3172 KB |
Output is correct |
46 |
Correct |
39 ms |
3168 KB |
Output is correct |
47 |
Correct |
37 ms |
3176 KB |
Output is correct |
48 |
Correct |
35 ms |
3172 KB |
Output is correct |
49 |
Correct |
24 ms |
2148 KB |
Output is correct |
50 |
Correct |
38 ms |
3060 KB |
Output is correct |
51 |
Correct |
35 ms |
3144 KB |
Output is correct |
52 |
Correct |
23 ms |
3072 KB |
Output is correct |
53 |
Correct |
27 ms |
3172 KB |
Output is correct |
54 |
Correct |
34 ms |
3172 KB |
Output is correct |
55 |
Correct |
23 ms |
3172 KB |
Output is correct |
56 |
Correct |
20 ms |
3172 KB |
Output is correct |