# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
569792 | 2022-05-27T19:59:10 Z | aryan12 | Painting Walls (APIO20_paint) | C++17 | 1500 ms | 164176 KB |
#include "paint.h" #include <bits/stdc++.h> using namespace std; int minimumInstructions(int N, int M, int K, vector<int> colors, vector<int> num, vector<vector<int> > likes) { vector<vector<int> > dp(N, vector<int> (M, -1e9)); set<int> likings[M]; for(int contractor = 0; contractor < M; contractor++) { for(int j = 0; j < num[contractor]; j++) { likings[contractor].insert(likes[contractor][j]); } } for(int i = N - 1; i >= 0; i--) { for(int j = 0; j < M; j++) { if(likings[j].count(colors[i])) { if(i == N - 1 || dp[i + 1][(j + 1) % M] == -1e9) { dp[i][j] = 1; } else { dp[i][j] = dp[i + 1][(j + 1) % M] + 1; } } // cout << "dp[" << i << "][" << j << "] = " << dp[i][j] << "\n"; } // cout << "\n\n\n\n"; } vector<int> start_pos; for(int i = N - M; i >= 0; i--) { for(int j = 0; j < M; j++) { if(dp[i][j] >= M) { start_pos.push_back(i); // cout << i << "\n"; break; } } } int ans = 0; int min_x = N; for(int i = 0; i < start_pos.size(); i++) { // cout << "start_pos[i] = " << start_pos[i] << ", M = " << M << ", minx = " << min_x << "\n"; if(start_pos[i] + M - 1 < min_x - 1) { return -1; } if(i == start_pos.size() - 1 || start_pos[i + 1] + M - 1 < min_x - 1 || start_pos[i] == 0) { min_x = start_pos[i]; ans++; } } if(min_x != 0) return -1; return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 300 KB | Output is correct |
8 | Correct | 1 ms | 296 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 300 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 2 ms | 724 KB | Output is correct |
14 | Correct | 2 ms | 692 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 724 KB | Output is correct |
17 | Correct | 2 ms | 688 KB | Output is correct |
18 | Correct | 1 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 724 KB | Output is correct |
20 | Correct | 2 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 34 ms | 6756 KB | Output is correct |
23 | Correct | 40 ms | 6748 KB | Output is correct |
24 | Correct | 39 ms | 6772 KB | Output is correct |
25 | Correct | 5 ms | 1692 KB | Output is correct |
26 | Correct | 4 ms | 1696 KB | Output is correct |
27 | Correct | 4 ms | 1620 KB | Output is correct |
28 | Correct | 5 ms | 1564 KB | Output is correct |
29 | Correct | 4 ms | 1492 KB | Output is correct |
30 | Correct | 4 ms | 1588 KB | Output is correct |
31 | Correct | 754 ms | 159476 KB | Output is correct |
32 | Correct | 755 ms | 159536 KB | Output is correct |
33 | Correct | 747 ms | 159476 KB | Output is correct |
34 | Correct | 730 ms | 159476 KB | Output is correct |
35 | Correct | 743 ms | 159536 KB | Output is correct |
36 | Correct | 745 ms | 159476 KB | Output is correct |
37 | Execution timed out | 1594 ms | 164176 KB | Time limit exceeded |
38 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 300 KB | Output is correct |
8 | Correct | 1 ms | 296 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 300 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 2 ms | 724 KB | Output is correct |
14 | Correct | 2 ms | 692 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 724 KB | Output is correct |
17 | Correct | 2 ms | 688 KB | Output is correct |
18 | Correct | 1 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 724 KB | Output is correct |
20 | Correct | 2 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 1 ms | 212 KB | Output is correct |
23 | Correct | 1 ms | 212 KB | Output is correct |
24 | Correct | 1 ms | 212 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 1 ms | 212 KB | Output is correct |
27 | Correct | 1 ms | 304 KB | Output is correct |
28 | Correct | 1 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 304 KB | Output is correct |
30 | Correct | 1 ms | 340 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 340 KB | Output is correct |
33 | Correct | 1 ms | 596 KB | Output is correct |
34 | Correct | 2 ms | 596 KB | Output is correct |
35 | Correct | 1 ms | 468 KB | Output is correct |
36 | Correct | 1 ms | 468 KB | Output is correct |
37 | Correct | 2 ms | 552 KB | Output is correct |
38 | Correct | 1 ms | 340 KB | Output is correct |
39 | Correct | 1 ms | 300 KB | Output is correct |
40 | Correct | 2 ms | 468 KB | Output is correct |
41 | Correct | 1 ms | 468 KB | Output is correct |
42 | Correct | 1 ms | 428 KB | Output is correct |
43 | Correct | 1 ms | 464 KB | Output is correct |
44 | Correct | 1 ms | 340 KB | Output is correct |
45 | Correct | 1 ms | 296 KB | Output is correct |
46 | Correct | 1 ms | 340 KB | Output is correct |
47 | Correct | 1 ms | 340 KB | Output is correct |
48 | Correct | 1 ms | 340 KB | Output is correct |
49 | Correct | 1 ms | 340 KB | Output is correct |
50 | Correct | 1 ms | 724 KB | Output is correct |
51 | Correct | 2 ms | 724 KB | Output is correct |
52 | Correct | 1 ms | 724 KB | Output is correct |
53 | Correct | 2 ms | 724 KB | Output is correct |
54 | Correct | 2 ms | 724 KB | Output is correct |
55 | Correct | 1 ms | 724 KB | Output is correct |
56 | Correct | 2 ms | 684 KB | Output is correct |
57 | Correct | 2 ms | 724 KB | Output is correct |
58 | Correct | 2 ms | 724 KB | Output is correct |
59 | Correct | 1 ms | 724 KB | Output is correct |
60 | Correct | 2 ms | 692 KB | Output is correct |
61 | Correct | 2 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 296 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 300 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 692 KB | Output is correct |
17 | Correct | 2 ms | 724 KB | Output is correct |
18 | Correct | 2 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 688 KB | Output is correct |
20 | Correct | 1 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 2 ms | 724 KB | Output is correct |
23 | Correct | 2 ms | 724 KB | Output is correct |
24 | Correct | 34 ms | 6756 KB | Output is correct |
25 | Correct | 40 ms | 6748 KB | Output is correct |
26 | Correct | 39 ms | 6772 KB | Output is correct |
27 | Correct | 1 ms | 212 KB | Output is correct |
28 | Correct | 0 ms | 212 KB | Output is correct |
29 | Correct | 1 ms | 212 KB | Output is correct |
30 | Correct | 1 ms | 304 KB | Output is correct |
31 | Correct | 1 ms | 340 KB | Output is correct |
32 | Correct | 1 ms | 304 KB | Output is correct |
33 | Correct | 1 ms | 340 KB | Output is correct |
34 | Correct | 1 ms | 340 KB | Output is correct |
35 | Correct | 1 ms | 340 KB | Output is correct |
36 | Correct | 1 ms | 596 KB | Output is correct |
37 | Correct | 2 ms | 596 KB | Output is correct |
38 | Correct | 1 ms | 468 KB | Output is correct |
39 | Correct | 1 ms | 468 KB | Output is correct |
40 | Correct | 2 ms | 552 KB | Output is correct |
41 | Correct | 1 ms | 340 KB | Output is correct |
42 | Correct | 1 ms | 300 KB | Output is correct |
43 | Correct | 2 ms | 468 KB | Output is correct |
44 | Correct | 1 ms | 468 KB | Output is correct |
45 | Correct | 1 ms | 428 KB | Output is correct |
46 | Correct | 1 ms | 464 KB | Output is correct |
47 | Correct | 1 ms | 340 KB | Output is correct |
48 | Correct | 1 ms | 296 KB | Output is correct |
49 | Correct | 1 ms | 340 KB | Output is correct |
50 | Correct | 1 ms | 340 KB | Output is correct |
51 | Correct | 1 ms | 340 KB | Output is correct |
52 | Correct | 1 ms | 340 KB | Output is correct |
53 | Correct | 1 ms | 724 KB | Output is correct |
54 | Correct | 2 ms | 724 KB | Output is correct |
55 | Correct | 1 ms | 724 KB | Output is correct |
56 | Correct | 2 ms | 724 KB | Output is correct |
57 | Correct | 2 ms | 724 KB | Output is correct |
58 | Correct | 1 ms | 724 KB | Output is correct |
59 | Correct | 2 ms | 684 KB | Output is correct |
60 | Correct | 2 ms | 724 KB | Output is correct |
61 | Correct | 2 ms | 724 KB | Output is correct |
62 | Correct | 1 ms | 724 KB | Output is correct |
63 | Correct | 2 ms | 692 KB | Output is correct |
64 | Correct | 2 ms | 724 KB | Output is correct |
65 | Correct | 1 ms | 468 KB | Output is correct |
66 | Correct | 1 ms | 296 KB | Output is correct |
67 | Correct | 2 ms | 596 KB | Output is correct |
68 | Correct | 1 ms | 468 KB | Output is correct |
69 | Correct | 1 ms | 468 KB | Output is correct |
70 | Correct | 6 ms | 1236 KB | Output is correct |
71 | Correct | 6 ms | 1276 KB | Output is correct |
72 | Correct | 5 ms | 1096 KB | Output is correct |
73 | Correct | 3 ms | 596 KB | Output is correct |
74 | Correct | 5 ms | 1108 KB | Output is correct |
75 | Correct | 4 ms | 980 KB | Output is correct |
76 | Correct | 31 ms | 7120 KB | Output is correct |
77 | Correct | 37 ms | 7640 KB | Output is correct |
78 | Correct | 39 ms | 8976 KB | Output is correct |
79 | Correct | 2 ms | 724 KB | Output is correct |
80 | Correct | 2 ms | 724 KB | Output is correct |
81 | Correct | 2 ms | 724 KB | Output is correct |
82 | Correct | 1 ms | 724 KB | Output is correct |
83 | Correct | 2 ms | 724 KB | Output is correct |
84 | Correct | 9 ms | 1592 KB | Output is correct |
85 | Correct | 8 ms | 1588 KB | Output is correct |
86 | Correct | 8 ms | 1580 KB | Output is correct |
87 | Correct | 7 ms | 1492 KB | Output is correct |
88 | Correct | 8 ms | 1580 KB | Output is correct |
89 | Correct | 8 ms | 1492 KB | Output is correct |
90 | Correct | 58 ms | 10172 KB | Output is correct |
91 | Correct | 54 ms | 10036 KB | Output is correct |
92 | Correct | 50 ms | 10140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 296 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 300 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 692 KB | Output is correct |
17 | Correct | 2 ms | 724 KB | Output is correct |
18 | Correct | 2 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 688 KB | Output is correct |
20 | Correct | 1 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 2 ms | 724 KB | Output is correct |
23 | Correct | 2 ms | 724 KB | Output is correct |
24 | Correct | 34 ms | 6756 KB | Output is correct |
25 | Correct | 40 ms | 6748 KB | Output is correct |
26 | Correct | 39 ms | 6772 KB | Output is correct |
27 | Correct | 5 ms | 1692 KB | Output is correct |
28 | Correct | 4 ms | 1696 KB | Output is correct |
29 | Correct | 4 ms | 1620 KB | Output is correct |
30 | Correct | 5 ms | 1564 KB | Output is correct |
31 | Correct | 4 ms | 1492 KB | Output is correct |
32 | Correct | 4 ms | 1588 KB | Output is correct |
33 | Correct | 754 ms | 159476 KB | Output is correct |
34 | Correct | 755 ms | 159536 KB | Output is correct |
35 | Correct | 747 ms | 159476 KB | Output is correct |
36 | Correct | 730 ms | 159476 KB | Output is correct |
37 | Correct | 743 ms | 159536 KB | Output is correct |
38 | Correct | 745 ms | 159476 KB | Output is correct |
39 | Execution timed out | 1594 ms | 164176 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 300 KB | Output is correct |
10 | Correct | 1 ms | 296 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 300 KB | Output is correct |
14 | Correct | 1 ms | 212 KB | Output is correct |
15 | Correct | 2 ms | 724 KB | Output is correct |
16 | Correct | 2 ms | 692 KB | Output is correct |
17 | Correct | 2 ms | 724 KB | Output is correct |
18 | Correct | 2 ms | 724 KB | Output is correct |
19 | Correct | 2 ms | 688 KB | Output is correct |
20 | Correct | 1 ms | 724 KB | Output is correct |
21 | Correct | 2 ms | 724 KB | Output is correct |
22 | Correct | 2 ms | 724 KB | Output is correct |
23 | Correct | 2 ms | 724 KB | Output is correct |
24 | Correct | 34 ms | 6756 KB | Output is correct |
25 | Correct | 40 ms | 6748 KB | Output is correct |
26 | Correct | 39 ms | 6772 KB | Output is correct |
27 | Correct | 5 ms | 1692 KB | Output is correct |
28 | Correct | 4 ms | 1696 KB | Output is correct |
29 | Correct | 4 ms | 1620 KB | Output is correct |
30 | Correct | 5 ms | 1564 KB | Output is correct |
31 | Correct | 4 ms | 1492 KB | Output is correct |
32 | Correct | 4 ms | 1588 KB | Output is correct |
33 | Correct | 754 ms | 159476 KB | Output is correct |
34 | Correct | 755 ms | 159536 KB | Output is correct |
35 | Correct | 747 ms | 159476 KB | Output is correct |
36 | Correct | 730 ms | 159476 KB | Output is correct |
37 | Correct | 743 ms | 159536 KB | Output is correct |
38 | Correct | 745 ms | 159476 KB | Output is correct |
39 | Execution timed out | 1594 ms | 164176 KB | Time limit exceeded |
40 | Halted | 0 ms | 0 KB | - |