# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1015221 |
2024-07-06T07:39:06 Z |
aufan |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
34 ms |
12060 KB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
using namespace std;
const int inf = 1e9;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
string s;
cin >> s;
s = '?' + s;
vector<vector<int>> pref(n + 1, vector<int>(3));
for (int i = 1; i <= n; i++) {
pref[i] = pref[i - 1];
if (s[i] == 'J') pref[i][0] += 1;
if (s[i] == 'O') pref[i][1] += 1;
if (s[i] == 'I') pref[i][2] += 1;
}
int p = 1, ans = inf;
for (int i = 1; i <= n; i++) {
while (p + 1 <= n && pref[p][1] - pref[i - 1][1] < k) p += 1;
if (pref[p][1] - pref[i - 1][1] < k) break;
int lf = 1, rg = i - 1, pl = -1;
while (lf <= rg) {
int md = (lf + rg) / 2;
if (pref[i - 1][0] - pref[md - 1][0] >= k) {
pl = md;
lf = md + 1;
} else {
rg = md - 1;
}
}
if (pl == -1) continue;
int pr = -1;
lf = p + 1, rg = n;
while (lf <= rg) {
int md = (lf + rg) / 2;
if (pref[md][2] - pref[p][2] >= k) {
pr = md;
rg = md - 1;
} else {
lf = md + 1;
}
}
if (pr == -1) continue;
ans = min(ans, (pr - pl + 1) - 3 * k);
}
cout << (ans == inf ? -1 : ans) << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
560 KB |
Output is correct |
28 |
Correct |
1 ms |
456 KB |
Output is correct |
29 |
Correct |
1 ms |
456 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
452 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
0 ms |
456 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
456 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
604 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
456 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
604 KB |
Output is correct |
25 |
Correct |
1 ms |
604 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
560 KB |
Output is correct |
28 |
Correct |
1 ms |
456 KB |
Output is correct |
29 |
Correct |
1 ms |
456 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
604 KB |
Output is correct |
33 |
Correct |
1 ms |
604 KB |
Output is correct |
34 |
Correct |
0 ms |
604 KB |
Output is correct |
35 |
Correct |
1 ms |
604 KB |
Output is correct |
36 |
Correct |
28 ms |
11032 KB |
Output is correct |
37 |
Correct |
26 ms |
11812 KB |
Output is correct |
38 |
Correct |
34 ms |
11744 KB |
Output is correct |
39 |
Correct |
28 ms |
11556 KB |
Output is correct |
40 |
Correct |
22 ms |
11812 KB |
Output is correct |
41 |
Correct |
25 ms |
11808 KB |
Output is correct |
42 |
Correct |
32 ms |
11812 KB |
Output is correct |
43 |
Correct |
11 ms |
7516 KB |
Output is correct |
44 |
Correct |
16 ms |
9156 KB |
Output is correct |
45 |
Correct |
20 ms |
11812 KB |
Output is correct |
46 |
Correct |
18 ms |
11704 KB |
Output is correct |
47 |
Correct |
17 ms |
11740 KB |
Output is correct |
48 |
Correct |
21 ms |
11828 KB |
Output is correct |
49 |
Correct |
12 ms |
7896 KB |
Output is correct |
50 |
Correct |
19 ms |
11808 KB |
Output is correct |
51 |
Correct |
18 ms |
11812 KB |
Output is correct |
52 |
Correct |
15 ms |
11392 KB |
Output is correct |
53 |
Correct |
13 ms |
12060 KB |
Output is correct |
54 |
Correct |
33 ms |
11812 KB |
Output is correct |
55 |
Correct |
14 ms |
11812 KB |
Output is correct |
56 |
Correct |
14 ms |
11592 KB |
Output is correct |