# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
207837 |
2020-03-09T08:36:11 Z |
pavement |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
34 ms |
3064 KB |
#include <bits/stdc++.h>
using namespace std;
int N, K, A = 1e9, C[5][200005];
char S[200005];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> N >> K;
for (int i = 1; i <= N; i++) cin >> S[i];
for (int i = N; i >= 1; i--) {
C[1][i] = C[1][i + 1];
C[2][i] = C[2][i + 1];
C[3][i] = C[3][i + 1];
if (S[i] == 'J') C[1][i]++;
else if (S[i] == 'O') C[2][i]++;
else C[3][i]++;
}
for (int i = 1; i <= N; i++) {
int lo = 1, hi = i - K + 1, ans = -1, cans;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (C[3][mid] - C[3][i + 1] >= K) ans = mid, lo = mid + 1;
else hi = mid - 1;
}
if (ans == -1) continue;
lo = 1, hi = ans - K + 1, cans = ans, ans = -1;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (C[2][mid] - C[2][cans + 1] >= K) ans = mid, lo = mid + 1;
else hi = mid - 1;
}
if (ans == -1) continue;
lo = 1, hi = ans - K + 1, cans = ans, ans = -1;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (C[1][mid] - C[1][cans + 1] >= K) ans = mid, lo = mid + 1;
else hi = mid - 1;
}
if (ans == -1) continue;
A = min(A, i - ans + 1);
}
cout << (A == 1e9 ? -1 : A - 3 * K) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 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 |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 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 |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 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 |
380 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 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 |
380 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 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 |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
376 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 |
380 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
5 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 |
380 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
5 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 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 |
29 ms |
2680 KB |
Output is correct |
37 |
Correct |
30 ms |
2936 KB |
Output is correct |
38 |
Correct |
31 ms |
2936 KB |
Output is correct |
39 |
Correct |
31 ms |
2808 KB |
Output is correct |
40 |
Correct |
23 ms |
2936 KB |
Output is correct |
41 |
Correct |
29 ms |
2936 KB |
Output is correct |
42 |
Correct |
34 ms |
2808 KB |
Output is correct |
43 |
Correct |
14 ms |
1912 KB |
Output is correct |
44 |
Correct |
17 ms |
2296 KB |
Output is correct |
45 |
Correct |
21 ms |
2936 KB |
Output is correct |
46 |
Correct |
21 ms |
2936 KB |
Output is correct |
47 |
Correct |
20 ms |
2936 KB |
Output is correct |
48 |
Correct |
21 ms |
2936 KB |
Output is correct |
49 |
Correct |
15 ms |
2040 KB |
Output is correct |
50 |
Correct |
21 ms |
2936 KB |
Output is correct |
51 |
Correct |
20 ms |
2808 KB |
Output is correct |
52 |
Correct |
13 ms |
2808 KB |
Output is correct |
53 |
Correct |
13 ms |
2936 KB |
Output is correct |
54 |
Correct |
19 ms |
2808 KB |
Output is correct |
55 |
Correct |
15 ms |
3064 KB |
Output is correct |
56 |
Correct |
11 ms |
2936 KB |
Output is correct |