# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
996565 |
2024-06-10T19:39:46 Z |
makrav |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
11 ms |
2660 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) a.size()
#define pb push_back
#define ff first
#define sc second
#define pii pair<int, int>
#define f(i, l, r) for (int i = (l); i < (r); i++)
#define double ld
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, k;
cin >> n >> k;
string s; cin >> s;
vector<int> posj, posi, pref(n + 1);
for (int i = 0; i < n; i++) {
pref[i + 1] = pref[i];
if (s[i] == 'J') posj.push_back(i);
else if (s[i] == 'I') posi.push_back(i);
else {
pref[i + 1]++;
}
}
int ans = 1e9;
int ind = -1;
for (int i = 0; i < n; i++) {
if (s[i] == 'J' && ind+k<sz(posj)) {
ind++;
int L = -1, R = sz(posi);
while (R - L > 1) {
int M = (L + R) / 2;
if (M < (k - 1) || posi[M - k + 1] < posj[ind+k-1]) {
L = M;
continue;
}
int cntt = pref[posi[M - k + 1]] - pref[posj[ind+k-1]];
if (cntt>=k)R=M;
else L=M;
}
if (R < sz(posi)) ans = min(ans, n - 3 * k - i - (n - posi[R] - 1));
}
}
cout << (ans == 1e9 ? -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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
452 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 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 |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 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 |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
456 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
452 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
9 ms |
2068 KB |
Output is correct |
37 |
Correct |
10 ms |
2448 KB |
Output is correct |
38 |
Correct |
10 ms |
2660 KB |
Output is correct |
39 |
Correct |
11 ms |
2524 KB |
Output is correct |
40 |
Correct |
7 ms |
2476 KB |
Output is correct |
41 |
Correct |
8 ms |
2404 KB |
Output is correct |
42 |
Correct |
9 ms |
2488 KB |
Output is correct |
43 |
Correct |
5 ms |
1752 KB |
Output is correct |
44 |
Correct |
6 ms |
1892 KB |
Output is correct |
45 |
Correct |
7 ms |
2348 KB |
Output is correct |
46 |
Correct |
6 ms |
2512 KB |
Output is correct |
47 |
Correct |
7 ms |
2480 KB |
Output is correct |
48 |
Correct |
7 ms |
2404 KB |
Output is correct |
49 |
Correct |
4 ms |
1684 KB |
Output is correct |
50 |
Correct |
7 ms |
2388 KB |
Output is correct |
51 |
Correct |
7 ms |
2508 KB |
Output is correct |
52 |
Correct |
4 ms |
2108 KB |
Output is correct |
53 |
Correct |
5 ms |
2404 KB |
Output is correct |
54 |
Correct |
9 ms |
2548 KB |
Output is correct |
55 |
Correct |
3 ms |
2656 KB |
Output is correct |
56 |
Correct |
2 ms |
2516 KB |
Output is correct |