# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
892760 | 2023-12-25T22:05:11 Z | betterdanjoe | Painting Walls (APIO20_paint) | C++17 | 56 ms | 23600 KB |
#ifndef LOCAL #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx,avx2,fma") #endif #include <bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef pair<ld, ld> pld; const int INF = 1e9; const ll LLINF = 1e18; const int MOD = 1e9 + 7; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { vector<int> pos[K]; for(int i = 0; i < N; i++){ pos[C[i]].pb(i); } vector<int> val[N]; vector<int> len[N]; for(int i = 0; i < M; i++){ for(int j : B[i]){ for(int k : pos[j]){ val[k].pb(i); } } } for(int i = 0; i < N; i++) len[i].resize(val[i].size(), 0); for(int i = N - 1; i >= 1; i--){ int ind = 0; for(int j = 0; j < val[i].size(); j++){ while(ind < val[i - 1].size() && val[i - 1][ind] < val[i][j] - 1) ind++; if(ind < val[i - 1].size() && val[i - 1][ind] == val[i][j] - 1){ len[i - 1][ind] = len[i][j] + 1; } } } bool check[N]; memset(check, false, sizeof(check)); for(int i = 0; i < N - M + 1; i++){ for(int j = 0; j < val[i].size(); j++){ if(len[i][j] == M - 1){ check[i] = true; break; } if(len[i][j] == M - 1 - val[i][j] && val[i + len[i][j] + 1][0] == 0 && len[i + len[i][j] + 1][0] >= val[i][j] - 1){ check[i] = true; break; } } } int cur = 0; int prv = 0; int ans = 0; while(cur < N){ int nxt = -1; for(int i = prv; i <= cur; i++){ if(check[i]) nxt = i + M; } if(nxt == -1) return -1; ans++; prv = cur + 1; cur = nxt; } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 2644 KB | Output is correct |
14 | Correct | 2 ms | 2652 KB | Output is correct |
15 | Correct | 2 ms | 2648 KB | Output is correct |
16 | Correct | 2 ms | 2648 KB | Output is correct |
17 | Correct | 2 ms | 2652 KB | Output is correct |
18 | Correct | 2 ms | 2652 KB | Output is correct |
19 | Correct | 2 ms | 2652 KB | Output is correct |
20 | Correct | 2 ms | 2652 KB | Output is correct |
21 | Correct | 2 ms | 2652 KB | Output is correct |
22 | Correct | 9 ms | 3420 KB | Output is correct |
23 | Correct | 9 ms | 3640 KB | Output is correct |
24 | Correct | 9 ms | 3420 KB | Output is correct |
25 | Correct | 4 ms | 2652 KB | Output is correct |
26 | Correct | 4 ms | 2652 KB | Output is correct |
27 | Correct | 4 ms | 2652 KB | Output is correct |
28 | Correct | 4 ms | 2648 KB | Output is correct |
29 | Correct | 4 ms | 3108 KB | Output is correct |
30 | Correct | 4 ms | 2652 KB | Output is correct |
31 | Correct | 10 ms | 6068 KB | Output is correct |
32 | Correct | 10 ms | 5960 KB | Output is correct |
33 | Correct | 10 ms | 5976 KB | Output is correct |
34 | Correct | 9 ms | 5976 KB | Output is correct |
35 | Correct | 10 ms | 5980 KB | Output is correct |
36 | Correct | 9 ms | 5980 KB | Output is correct |
37 | Correct | 16 ms | 6488 KB | Output is correct |
38 | Correct | 16 ms | 6492 KB | Output is correct |
39 | Correct | 16 ms | 6492 KB | Output is correct |
40 | Correct | 18 ms | 11476 KB | Output is correct |
41 | Correct | 12 ms | 7192 KB | Output is correct |
42 | Correct | 20 ms | 12248 KB | Output is correct |
43 | Correct | 14 ms | 8284 KB | Output is correct |
44 | Correct | 12 ms | 7516 KB | Output is correct |
45 | Correct | 21 ms | 12572 KB | Output is correct |
46 | Correct | 45 ms | 21332 KB | Output is correct |
47 | Correct | 27 ms | 13648 KB | Output is correct |
48 | Correct | 31 ms | 15964 KB | Output is correct |
49 | Correct | 36 ms | 15416 KB | Output is correct |
50 | Correct | 42 ms | 16112 KB | Output is correct |
51 | Correct | 34 ms | 14420 KB | Output is correct |
52 | Correct | 19 ms | 12500 KB | Output is correct |
53 | Correct | 20 ms | 12500 KB | Output is correct |
54 | Correct | 21 ms | 12504 KB | Output is correct |
55 | Correct | 20 ms | 12724 KB | Output is correct |
56 | Correct | 20 ms | 12532 KB | Output is correct |
57 | Correct | 21 ms | 12636 KB | Output is correct |
58 | Correct | 49 ms | 23388 KB | Output is correct |
59 | Correct | 49 ms | 23600 KB | Output is correct |
60 | Correct | 49 ms | 23376 KB | Output is correct |
61 | Correct | 50 ms | 23376 KB | Output is correct |
62 | Correct | 52 ms | 23380 KB | Output is correct |
63 | Correct | 50 ms | 23480 KB | Output is correct |
64 | Correct | 53 ms | 21444 KB | Output is correct |
65 | Correct | 56 ms | 21564 KB | Output is correct |
66 | Correct | 55 ms | 21568 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 344 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 0 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 2644 KB | Output is correct |
14 | Correct | 2 ms | 2652 KB | Output is correct |
15 | Correct | 2 ms | 2648 KB | Output is correct |
16 | Correct | 2 ms | 2648 KB | Output is correct |
17 | Correct | 2 ms | 2652 KB | Output is correct |
18 | Correct | 2 ms | 2652 KB | Output is correct |
19 | Correct | 2 ms | 2652 KB | Output is correct |
20 | Correct | 2 ms | 2652 KB | Output is correct |
21 | Correct | 2 ms | 2652 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 | Runtime error | 0 ms | 348 KB | Execution killed with signal 11 |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 2 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2652 KB | Output is correct |
17 | Correct | 2 ms | 2648 KB | Output is correct |
18 | Correct | 2 ms | 2648 KB | Output is correct |
19 | Correct | 2 ms | 2652 KB | Output is correct |
20 | Correct | 2 ms | 2652 KB | Output is correct |
21 | Correct | 2 ms | 2652 KB | Output is correct |
22 | Correct | 2 ms | 2652 KB | Output is correct |
23 | Correct | 2 ms | 2652 KB | Output is correct |
24 | Correct | 9 ms | 3420 KB | Output is correct |
25 | Correct | 9 ms | 3640 KB | Output is correct |
26 | Correct | 9 ms | 3420 KB | Output is correct |
27 | Correct | 0 ms | 348 KB | Output is correct |
28 | Runtime error | 0 ms | 348 KB | Execution killed with signal 11 |
29 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 2 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2652 KB | Output is correct |
17 | Correct | 2 ms | 2648 KB | Output is correct |
18 | Correct | 2 ms | 2648 KB | Output is correct |
19 | Correct | 2 ms | 2652 KB | Output is correct |
20 | Correct | 2 ms | 2652 KB | Output is correct |
21 | Correct | 2 ms | 2652 KB | Output is correct |
22 | Correct | 2 ms | 2652 KB | Output is correct |
23 | Correct | 2 ms | 2652 KB | Output is correct |
24 | Correct | 9 ms | 3420 KB | Output is correct |
25 | Correct | 9 ms | 3640 KB | Output is correct |
26 | Correct | 9 ms | 3420 KB | Output is correct |
27 | Correct | 4 ms | 2652 KB | Output is correct |
28 | Correct | 4 ms | 2652 KB | Output is correct |
29 | Correct | 4 ms | 2652 KB | Output is correct |
30 | Correct | 4 ms | 2648 KB | Output is correct |
31 | Correct | 4 ms | 3108 KB | Output is correct |
32 | Correct | 4 ms | 2652 KB | Output is correct |
33 | Correct | 10 ms | 6068 KB | Output is correct |
34 | Correct | 10 ms | 5960 KB | Output is correct |
35 | Correct | 10 ms | 5976 KB | Output is correct |
36 | Correct | 9 ms | 5976 KB | Output is correct |
37 | Correct | 10 ms | 5980 KB | Output is correct |
38 | Correct | 9 ms | 5980 KB | Output is correct |
39 | Correct | 16 ms | 6488 KB | Output is correct |
40 | Correct | 16 ms | 6492 KB | Output is correct |
41 | Correct | 16 ms | 6492 KB | Output is correct |
42 | Correct | 0 ms | 348 KB | Output is correct |
43 | Runtime error | 0 ms | 348 KB | Execution killed with signal 11 |
44 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 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 | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 0 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 0 ms | 348 KB | Output is correct |
15 | Correct | 2 ms | 2644 KB | Output is correct |
16 | Correct | 2 ms | 2652 KB | Output is correct |
17 | Correct | 2 ms | 2648 KB | Output is correct |
18 | Correct | 2 ms | 2648 KB | Output is correct |
19 | Correct | 2 ms | 2652 KB | Output is correct |
20 | Correct | 2 ms | 2652 KB | Output is correct |
21 | Correct | 2 ms | 2652 KB | Output is correct |
22 | Correct | 2 ms | 2652 KB | Output is correct |
23 | Correct | 2 ms | 2652 KB | Output is correct |
24 | Correct | 9 ms | 3420 KB | Output is correct |
25 | Correct | 9 ms | 3640 KB | Output is correct |
26 | Correct | 9 ms | 3420 KB | Output is correct |
27 | Correct | 4 ms | 2652 KB | Output is correct |
28 | Correct | 4 ms | 2652 KB | Output is correct |
29 | Correct | 4 ms | 2652 KB | Output is correct |
30 | Correct | 4 ms | 2648 KB | Output is correct |
31 | Correct | 4 ms | 3108 KB | Output is correct |
32 | Correct | 4 ms | 2652 KB | Output is correct |
33 | Correct | 10 ms | 6068 KB | Output is correct |
34 | Correct | 10 ms | 5960 KB | Output is correct |
35 | Correct | 10 ms | 5976 KB | Output is correct |
36 | Correct | 9 ms | 5976 KB | Output is correct |
37 | Correct | 10 ms | 5980 KB | Output is correct |
38 | Correct | 9 ms | 5980 KB | Output is correct |
39 | Correct | 16 ms | 6488 KB | Output is correct |
40 | Correct | 16 ms | 6492 KB | Output is correct |
41 | Correct | 16 ms | 6492 KB | Output is correct |
42 | Correct | 18 ms | 11476 KB | Output is correct |
43 | Correct | 12 ms | 7192 KB | Output is correct |
44 | Correct | 20 ms | 12248 KB | Output is correct |
45 | Correct | 14 ms | 8284 KB | Output is correct |
46 | Correct | 12 ms | 7516 KB | Output is correct |
47 | Correct | 21 ms | 12572 KB | Output is correct |
48 | Correct | 45 ms | 21332 KB | Output is correct |
49 | Correct | 27 ms | 13648 KB | Output is correct |
50 | Correct | 31 ms | 15964 KB | Output is correct |
51 | Correct | 36 ms | 15416 KB | Output is correct |
52 | Correct | 42 ms | 16112 KB | Output is correct |
53 | Correct | 34 ms | 14420 KB | Output is correct |
54 | Correct | 19 ms | 12500 KB | Output is correct |
55 | Correct | 20 ms | 12500 KB | Output is correct |
56 | Correct | 21 ms | 12504 KB | Output is correct |
57 | Correct | 20 ms | 12724 KB | Output is correct |
58 | Correct | 20 ms | 12532 KB | Output is correct |
59 | Correct | 21 ms | 12636 KB | Output is correct |
60 | Correct | 49 ms | 23388 KB | Output is correct |
61 | Correct | 49 ms | 23600 KB | Output is correct |
62 | Correct | 49 ms | 23376 KB | Output is correct |
63 | Correct | 50 ms | 23376 KB | Output is correct |
64 | Correct | 52 ms | 23380 KB | Output is correct |
65 | Correct | 50 ms | 23480 KB | Output is correct |
66 | Correct | 53 ms | 21444 KB | Output is correct |
67 | Correct | 56 ms | 21564 KB | Output is correct |
68 | Correct | 55 ms | 21568 KB | Output is correct |
69 | Correct | 0 ms | 348 KB | Output is correct |
70 | Runtime error | 0 ms | 348 KB | Execution killed with signal 11 |
71 | Halted | 0 ms | 0 KB | - |