# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203122 | 2020-02-19T12:44:18 Z | ZwariowanyMarcin | JJOOII 2 (JOI20_ho_t2) | C++14 | 13 ms | 3436 KB |
#include <bits/stdc++.h> #define LL long long #define pb push_back #define mp make_pair #define ss(x) (int) x.size() #define fi first #define se second #define cat(x) cerr << #x << " = " << x << endl #define rep(i, j, n) for (int i = j; i <= n; ++i) #define per(i, j, n) for (int i = n; j <= i; --i) using namespace std; const int nax = 2e5 + 111; const int INF = 1e9 + 11; int n, k; char s[nax]; vector <int> v[3]; int J[nax]; int I[nax]; int main() { scanf ("%d%d", &n, &k); scanf ("%s", s + 1); int a = 0, b = 0; rep(i, 1, n) { if (s[i] == 'J') v[0].pb(i), ++a; if (s[i] == 'O') v[1].pb(i); if (s[i] == 'I') v[2].pb(i), ++b; J[i] = a; I[i] = b; } int best = INF; for (int i = 0; i + k - 1 < ss(v[1]); ++i) { int x = v[1][i]; int y = v[1][i + k - 1]; int l = (J[x] - k >= 0 ? v[0][J[x] - k] : -1); int r = (I[y] + k - 1 < ss(v[2]) ? v[2][I[y] + k - 1] : -1); if (l == -1 || r == -1) continue; //printf ("%d %d %d %d\n", i, l, r, x); best = min(best, r - l + 1); } if (best == INF) printf ("-1\n"); else printf ("%d\n", best - 3 * k); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 248 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 380 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 | 256 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 248 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 380 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 | 256 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 | 376 KB | Output is correct |
25 | Correct | 5 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 504 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 | 504 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 | 4 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 256 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 256 KB | Output is correct |
6 | Correct | 5 ms | 256 KB | Output is correct |
7 | Correct | 4 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 248 KB | Output is correct |
9 | Correct | 5 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 380 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 | 256 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 | 376 KB | Output is correct |
25 | Correct | 5 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 504 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 | 504 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 | 10 ms | 2804 KB | Output is correct |
37 | Correct | 10 ms | 3308 KB | Output is correct |
38 | Correct | 11 ms | 3188 KB | Output is correct |
39 | Correct | 10 ms | 3316 KB | Output is correct |
40 | Correct | 10 ms | 3188 KB | Output is correct |
41 | Correct | 13 ms | 3188 KB | Output is correct |
42 | Correct | 11 ms | 3312 KB | Output is correct |
43 | Correct | 8 ms | 2164 KB | Output is correct |
44 | Correct | 9 ms | 2420 KB | Output is correct |
45 | Correct | 10 ms | 3184 KB | Output is correct |
46 | Correct | 11 ms | 3176 KB | Output is correct |
47 | Correct | 10 ms | 3192 KB | Output is correct |
48 | Correct | 10 ms | 3320 KB | Output is correct |
49 | Correct | 8 ms | 2164 KB | Output is correct |
50 | Correct | 10 ms | 3188 KB | Output is correct |
51 | Correct | 10 ms | 3188 KB | Output is correct |
52 | Correct | 9 ms | 2936 KB | Output is correct |
53 | Correct | 10 ms | 3304 KB | Output is correct |
54 | Correct | 9 ms | 3308 KB | Output is correct |
55 | Correct | 9 ms | 3436 KB | Output is correct |
56 | Correct | 8 ms | 3312 KB | Output is correct |