# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
571893 | 2022-06-03T05:53:06 Z | dantoh000 | JJOOII 2 (JOI20_ho_t2) | C++14 | 11 ms | 3364 KB |
#include <bits/stdc++.h> using namespace std; int n,k; string s; int nx[200005]; int jmp[200005]; vector<int> J, O, I; int main(){ scanf("%d%d",&n,&k); cin >> s; for (int i = 0; i < n; i++){ if (s[i] == 'J') J.push_back(i); if (s[i] == 'O') O.push_back(i); if (s[i] == 'I') I.push_back(i); } int lastI = -1, lastO = -1; memset(nx,-1,sizeof(nx)); for (int i = n-1; i >= 0; i--){ if (s[i] == 'I') lastI = i; if (s[i] == 'O') { nx[i] = lastI; lastO = i; } if (s[i] == 'J'){ nx[i] = lastO; } } memset(jmp,-1,sizeof(jmp)); for (int i = 0; i < J.size()-k+1; i++){ jmp[J[i]] = J[i+k-1]; } for (int i = 0; i < O.size()-k+1; i++){ jmp[O[i]] = O[i+k-1]; } for (int i = 0; i < I.size()-k+1; i++){ jmp[I[i]] = I[i+k-1]; } int ans = -1; for (int i = 0; i < J.size()-k+1; i++){ int lastJ = jmp[J[i]]; int firstO = nx[lastJ]; if (firstO == -1) continue; int lastO = jmp[firstO]; if (lastO == -1) continue; int firstI = nx[lastO]; if (firstI == -1) continue; int lastI = jmp[firstI]; if (lastI == -1) continue; int cost = lastI - J[i] + 1 - 3*k; if (ans == -1 || ans > cost) ans = cost; } printf("%d\n",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1748 KB | Output is correct |
2 | Correct | 1 ms | 1748 KB | Output is correct |
3 | Correct | 1 ms | 1748 KB | Output is correct |
4 | Correct | 1 ms | 1748 KB | Output is correct |
5 | Correct | 1 ms | 1748 KB | Output is correct |
6 | Correct | 1 ms | 1844 KB | Output is correct |
7 | Correct | 1 ms | 1748 KB | Output is correct |
8 | Correct | 1 ms | 1876 KB | Output is correct |
9 | Correct | 1 ms | 1748 KB | Output is correct |
10 | Correct | 1 ms | 1748 KB | Output is correct |
11 | Correct | 1 ms | 1876 KB | Output is correct |
12 | Correct | 1 ms | 1748 KB | Output is correct |
13 | Correct | 1 ms | 1748 KB | Output is correct |
14 | Correct | 2 ms | 1848 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1748 KB | Output is correct |
2 | Correct | 1 ms | 1748 KB | Output is correct |
3 | Correct | 1 ms | 1748 KB | Output is correct |
4 | Correct | 1 ms | 1748 KB | Output is correct |
5 | Correct | 1 ms | 1748 KB | Output is correct |
6 | Correct | 1 ms | 1844 KB | Output is correct |
7 | Correct | 1 ms | 1748 KB | Output is correct |
8 | Correct | 1 ms | 1876 KB | Output is correct |
9 | Correct | 1 ms | 1748 KB | Output is correct |
10 | Correct | 1 ms | 1748 KB | Output is correct |
11 | Correct | 1 ms | 1876 KB | Output is correct |
12 | Correct | 1 ms | 1748 KB | Output is correct |
13 | Correct | 1 ms | 1748 KB | Output is correct |
14 | Correct | 2 ms | 1848 KB | Output is correct |
15 | Correct | 1 ms | 1876 KB | Output is correct |
16 | Correct | 1 ms | 1876 KB | Output is correct |
17 | Correct | 1 ms | 1876 KB | Output is correct |
18 | Correct | 1 ms | 1876 KB | Output is correct |
19 | Correct | 1 ms | 1876 KB | Output is correct |
20 | Correct | 1 ms | 1876 KB | Output is correct |
21 | Correct | 2 ms | 1876 KB | Output is correct |
22 | Correct | 1 ms | 1876 KB | Output is correct |
23 | Correct | 1 ms | 1876 KB | Output is correct |
24 | Correct | 1 ms | 1876 KB | Output is correct |
25 | Correct | 1 ms | 1876 KB | Output is correct |
26 | Correct | 1 ms | 1876 KB | Output is correct |
27 | Correct | 1 ms | 1876 KB | Output is correct |
28 | Correct | 1 ms | 1876 KB | Output is correct |
29 | Correct | 1 ms | 1876 KB | Output is correct |
30 | Correct | 1 ms | 1840 KB | Output is correct |
31 | Correct | 1 ms | 1876 KB | Output is correct |
32 | Correct | 2 ms | 1876 KB | Output is correct |
33 | Correct | 1 ms | 1792 KB | Output is correct |
34 | Correct | 1 ms | 1876 KB | Output is correct |
35 | Correct | 1 ms | 1876 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 1748 KB | Output is correct |
2 | Correct | 1 ms | 1748 KB | Output is correct |
3 | Correct | 1 ms | 1748 KB | Output is correct |
4 | Correct | 1 ms | 1748 KB | Output is correct |
5 | Correct | 1 ms | 1748 KB | Output is correct |
6 | Correct | 1 ms | 1844 KB | Output is correct |
7 | Correct | 1 ms | 1748 KB | Output is correct |
8 | Correct | 1 ms | 1876 KB | Output is correct |
9 | Correct | 1 ms | 1748 KB | Output is correct |
10 | Correct | 1 ms | 1748 KB | Output is correct |
11 | Correct | 1 ms | 1876 KB | Output is correct |
12 | Correct | 1 ms | 1748 KB | Output is correct |
13 | Correct | 1 ms | 1748 KB | Output is correct |
14 | Correct | 2 ms | 1848 KB | Output is correct |
15 | Correct | 1 ms | 1876 KB | Output is correct |
16 | Correct | 1 ms | 1876 KB | Output is correct |
17 | Correct | 1 ms | 1876 KB | Output is correct |
18 | Correct | 1 ms | 1876 KB | Output is correct |
19 | Correct | 1 ms | 1876 KB | Output is correct |
20 | Correct | 1 ms | 1876 KB | Output is correct |
21 | Correct | 2 ms | 1876 KB | Output is correct |
22 | Correct | 1 ms | 1876 KB | Output is correct |
23 | Correct | 1 ms | 1876 KB | Output is correct |
24 | Correct | 1 ms | 1876 KB | Output is correct |
25 | Correct | 1 ms | 1876 KB | Output is correct |
26 | Correct | 1 ms | 1876 KB | Output is correct |
27 | Correct | 1 ms | 1876 KB | Output is correct |
28 | Correct | 1 ms | 1876 KB | Output is correct |
29 | Correct | 1 ms | 1876 KB | Output is correct |
30 | Correct | 1 ms | 1840 KB | Output is correct |
31 | Correct | 1 ms | 1876 KB | Output is correct |
32 | Correct | 2 ms | 1876 KB | Output is correct |
33 | Correct | 1 ms | 1792 KB | Output is correct |
34 | Correct | 1 ms | 1876 KB | Output is correct |
35 | Correct | 1 ms | 1876 KB | Output is correct |
36 | Correct | 9 ms | 3012 KB | Output is correct |
37 | Correct | 10 ms | 3196 KB | Output is correct |
38 | Correct | 10 ms | 3232 KB | Output is correct |
39 | Correct | 11 ms | 3240 KB | Output is correct |
40 | Correct | 11 ms | 3284 KB | Output is correct |
41 | Correct | 10 ms | 3196 KB | Output is correct |
42 | Correct | 10 ms | 3364 KB | Output is correct |
43 | Correct | 6 ms | 2776 KB | Output is correct |
44 | Correct | 8 ms | 3036 KB | Output is correct |
45 | Correct | 9 ms | 3260 KB | Output is correct |
46 | Correct | 11 ms | 3236 KB | Output is correct |
47 | Correct | 10 ms | 3252 KB | Output is correct |
48 | Correct | 9 ms | 3320 KB | Output is correct |
49 | Correct | 7 ms | 2872 KB | Output is correct |
50 | Correct | 10 ms | 3136 KB | Output is correct |
51 | Correct | 10 ms | 3260 KB | Output is correct |
52 | Correct | 9 ms | 3136 KB | Output is correct |
53 | Correct | 9 ms | 3268 KB | Output is correct |
54 | Correct | 7 ms | 3172 KB | Output is correct |
55 | Correct | 7 ms | 3172 KB | Output is correct |
56 | Correct | 7 ms | 3172 KB | Output is correct |