# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
878476 |
2023-11-24T14:05:30 Z |
atom |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
6 ms |
1708 KB |
#include "bits/stdc++.h"
// @JASPER'S BOILERPLATE
using namespace std;
using ll = long long;
#define fi first
#define se second
#ifdef JASPER
#include "debug.h"
#else
#define debug(...) 166
#endif
using pii = pair < int, int >;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
int n, k;
string s;
deque <int> q[3];
void run_case() {
cin >> n >> k >> s;
for (int i = 0; i < n; ++i) {
if (s[i] == 'J') q[0].push_back(i);
if (s[i] == 'O') q[1].push_back(i);
if (s[i] == 'I') q[2].push_back(i);
}
int ans = INF;
while ((int) q[0].size() >= k) {
// delete all Os sitting front of k Js
while ((int) q[1].size() > k && q[1].front() < q[0][k - 1])
q[1].pop_front();
// delete all Is front of k Os
while ((int) q[2].size() > k && (int) q[1].size() >= k && q[2].front() < q[1][k - 1])
q[2].pop_front();
if (q[0][k - 1] < q[1][0] && q[1][k - 1] < q[2][0]) {
int l = q[0].front();
int r = q[2][k - 1];
// debug(l, r);
// minimum operation 3
ans = min(ans, r - l + 1 - 3 * k);
}
q[0].pop_front();
}
if (ans == INF) ans = -1;
cout << ans << "\n";
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
int Test = 1;
//cin >> Test;
for (int test = 1; test <= Test; test++){
run_case();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 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 |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 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 |
0 ms |
348 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 |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 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 |
460 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
460 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 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 |
0 ms |
348 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 |
348 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 |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 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 |
460 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
460 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
4 ms |
1512 KB |
Output is correct |
37 |
Correct |
5 ms |
1512 KB |
Output is correct |
38 |
Correct |
5 ms |
1512 KB |
Output is correct |
39 |
Correct |
5 ms |
1532 KB |
Output is correct |
40 |
Correct |
4 ms |
1512 KB |
Output is correct |
41 |
Correct |
6 ms |
1508 KB |
Output is correct |
42 |
Correct |
6 ms |
1708 KB |
Output is correct |
43 |
Correct |
3 ms |
1116 KB |
Output is correct |
44 |
Correct |
3 ms |
1256 KB |
Output is correct |
45 |
Correct |
4 ms |
1508 KB |
Output is correct |
46 |
Correct |
4 ms |
1512 KB |
Output is correct |
47 |
Correct |
4 ms |
1508 KB |
Output is correct |
48 |
Correct |
4 ms |
1536 KB |
Output is correct |
49 |
Correct |
2 ms |
1256 KB |
Output is correct |
50 |
Correct |
4 ms |
1536 KB |
Output is correct |
51 |
Correct |
4 ms |
1512 KB |
Output is correct |
52 |
Correct |
3 ms |
1512 KB |
Output is correct |
53 |
Correct |
3 ms |
1512 KB |
Output is correct |
54 |
Correct |
3 ms |
1708 KB |
Output is correct |
55 |
Correct |
2 ms |
1512 KB |
Output is correct |
56 |
Correct |
2 ms |
1668 KB |
Output is correct |