# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203214 | 2020-02-19T20:07:31 Z | jovan_b | JJOOII 2 (JOI20_ho_t2) | C++17 | 12 ms | 3716 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; int dp1[200005]; int dp2[200005]; int dp3[200005]; int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, k; cin >> n >> k; string s; cin >> s; deque <int> q1, q2, q3; for(int i=n-1; i>=0; i--){ dp3[i] = n; dp2[i] = n; dp1[i] = n; if(s[i] == 'J'){ q1.push_front(i); if(q1.size() > k) q1.pop_back(); } if(s[i] == 'O'){ q2.push_front(i); if(q2.size() > k) q2.pop_back(); } if(s[i] == 'I'){ q3.push_front(i); if(q3.size() > k) q3.pop_back(); } if(q1.size() == k) dp1[i] = q1.back(); if(q2.size() == k) dp2[i] = q2.back(); if(q3.size() == k) dp3[i] = q3.back(); } int res = n+5; for(int i=0; i<n; i++){ int j = dp1[i]+1; if(j >= n) continue; j = dp2[j]+1; if(j >= n) continue; j = dp3[j]; if(j >= n) continue; res = min(res, j-i+1); } if(res == n+5){ cout << -1; return 0; } cout << res-3*k; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 7 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 6 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 | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 376 KB | Output is correct |
2 | Correct | 7 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 6 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 | 376 KB | Output is correct |
15 | Correct | 6 ms | 376 KB | Output is correct |
16 | Correct | 6 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 | 6 ms | 376 KB | Output is correct |
25 | Correct | 6 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 376 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 | 376 KB | Output is correct |
32 | Correct | 5 ms | 376 KB | Output is correct |
33 | Correct | 6 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 | 7 ms | 376 KB | Output is correct |
3 | Correct | 5 ms | 376 KB | Output is correct |
4 | Correct | 5 ms | 376 KB | Output is correct |
5 | Correct | 5 ms | 376 KB | Output is correct |
6 | Correct | 5 ms | 376 KB | Output is correct |
7 | Correct | 5 ms | 376 KB | Output is correct |
8 | Correct | 5 ms | 376 KB | Output is correct |
9 | Correct | 6 ms | 376 KB | Output is correct |
10 | Correct | 5 ms | 376 KB | Output is correct |
11 | Correct | 6 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 | 376 KB | Output is correct |
15 | Correct | 6 ms | 376 KB | Output is correct |
16 | Correct | 6 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 | 6 ms | 376 KB | Output is correct |
25 | Correct | 6 ms | 376 KB | Output is correct |
26 | Correct | 5 ms | 376 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 | 376 KB | Output is correct |
32 | Correct | 5 ms | 376 KB | Output is correct |
33 | Correct | 6 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 | 11 ms | 2820 KB | Output is correct |
37 | Correct | 12 ms | 3076 KB | Output is correct |
38 | Correct | 12 ms | 2948 KB | Output is correct |
39 | Correct | 11 ms | 2948 KB | Output is correct |
40 | Correct | 11 ms | 3072 KB | Output is correct |
41 | Correct | 12 ms | 3076 KB | Output is correct |
42 | Correct | 11 ms | 3076 KB | Output is correct |
43 | Correct | 9 ms | 2172 KB | Output is correct |
44 | Correct | 10 ms | 2564 KB | Output is correct |
45 | Correct | 11 ms | 3204 KB | Output is correct |
46 | Correct | 12 ms | 3204 KB | Output is correct |
47 | Correct | 12 ms | 3204 KB | Output is correct |
48 | Correct | 12 ms | 3204 KB | Output is correct |
49 | Correct | 9 ms | 2180 KB | Output is correct |
50 | Correct | 11 ms | 3204 KB | Output is correct |
51 | Correct | 12 ms | 3204 KB | Output is correct |
52 | Correct | 11 ms | 3460 KB | Output is correct |
53 | Correct | 11 ms | 3592 KB | Output is correct |
54 | Correct | 10 ms | 3076 KB | Output is correct |
55 | Correct | 9 ms | 3460 KB | Output is correct |
56 | Correct | 9 ms | 3716 KB | Output is correct |