Submission #1021571

# Submission time Handle Problem Language Result Execution time Memory
1021571 2024-07-12T19:58:50 Z MohamedFaresNebili Painting Walls (APIO20_paint) C++14
28 / 100
1500 ms 20220 KB
#include <bits/stdc++.h>
     
        using namespace std;

        int N, M, K;
        vector<int> C, A;
        vector<vector<int>> B;
        vector<int> adj[100005];
        map<int, int> Key[50005];
        int DP[100005];

        int solve(int i) {
            if(i >= N) return 0;
            if(DP[i] != -1) return DP[i];
            int best = 1e9 + 7; 
            for(auto u : adj[C[i]]) {
                bool ok = true;
                for(int l = 0; l < M; l++) {
                    int col = (u + l) % M;
                    ok &= (Key[col][C[i + l]] == 1);
                }
                if(!ok) continue;
                for(int l = 0; l < M; l++)
                    best = min(best, 1 + solve(i + l + 1));
            }
            return DP[i] = best;
        }

        int minimumInstructions(int _N, int _M, int _K, vector<int> _C, vector<int> _A, vector<vector<int>> _B) {
            N = _N, M = _M, K = _K;
            swap(_C, C); swap(_A, A); swap(_B, B);
            for(int l = 0; l < N; l++) DP[l] = -1;
            for(int l = 0; l < M; l++) {
                for(int i = 0; i < A[l]; i++) {
                    adj[B[l][i]].push_back(l);
                    Key[l][B[l][i]] = 1;
                }
            }
            int res = solve(0);
            return (res == 1e9 + 7 ? -1 : res);
            return -1;
        }
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 5096 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 5004 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 4968 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 3 ms 5132 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5212 KB Output is correct
19 Correct 3 ms 5164 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 3 ms 5212 KB Output is correct
22 Correct 27 ms 14280 KB Output is correct
23 Correct 35 ms 14164 KB Output is correct
24 Correct 26 ms 14172 KB Output is correct
25 Correct 5 ms 8028 KB Output is correct
26 Correct 5 ms 8024 KB Output is correct
27 Correct 3 ms 5212 KB Output is correct
28 Correct 4 ms 5212 KB Output is correct
29 Correct 4 ms 5256 KB Output is correct
30 Correct 3 ms 5208 KB Output is correct
31 Correct 537 ms 9932 KB Output is correct
32 Correct 535 ms 9944 KB Output is correct
33 Correct 568 ms 10064 KB Output is correct
34 Correct 602 ms 10064 KB Output is correct
35 Correct 604 ms 10072 KB Output is correct
36 Correct 582 ms 10068 KB Output is correct
37 Correct 33 ms 14676 KB Output is correct
38 Correct 39 ms 14916 KB Output is correct
39 Correct 30 ms 14672 KB Output is correct
40 Correct 18 ms 19036 KB Output is correct
41 Correct 18 ms 13912 KB Output is correct
42 Correct 8 ms 6440 KB Output is correct
43 Correct 11 ms 6040 KB Output is correct
44 Correct 11 ms 5980 KB Output is correct
45 Correct 7 ms 6492 KB Output is correct
46 Execution timed out 1559 ms 20220 KB Time limit exceeded
47 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 2 ms 5096 KB Output is correct
4 Correct 2 ms 4956 KB Output is correct
5 Correct 3 ms 4956 KB Output is correct
6 Correct 3 ms 5004 KB Output is correct
7 Correct 2 ms 5212 KB Output is correct
8 Correct 2 ms 5212 KB Output is correct
9 Correct 2 ms 4968 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 2 ms 4956 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 3 ms 5212 KB Output is correct
14 Correct 3 ms 5212 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 3 ms 5132 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5212 KB Output is correct
19 Correct 3 ms 5164 KB Output is correct
20 Correct 2 ms 5212 KB Output is correct
21 Correct 3 ms 5212 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
23 Correct 2 ms 4956 KB Output is correct
24 Correct 3 ms 4952 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 4956 KB Output is correct
27 Correct 3 ms 5140 KB Output is correct
28 Correct 4 ms 5000 KB Output is correct
29 Correct 2 ms 4956 KB Output is correct
30 Correct 2 ms 4956 KB Output is correct
31 Correct 3 ms 4956 KB Output is correct
32 Correct 4 ms 4952 KB Output is correct
33 Correct 3 ms 5212 KB Output is correct
34 Correct 4 ms 5256 KB Output is correct
35 Correct 3 ms 5212 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 5 ms 5212 KB Output is correct
38 Correct 4 ms 5212 KB Output is correct
39 Correct 4 ms 5212 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 9 ms 6236 KB Output is correct
42 Correct 2 ms 5212 KB Output is correct
43 Correct 4 ms 4956 KB Output is correct
44 Correct 4 ms 5208 KB Output is correct
45 Correct 5 ms 5212 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 3 ms 5136 KB Output is correct
48 Correct 3 ms 4956 KB Output is correct
49 Correct 4 ms 4956 KB Output is correct
50 Correct 4 ms 5212 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 3 ms 5212 KB Output is correct
53 Correct 3 ms 5212 KB Output is correct
54 Correct 4 ms 5212 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 3 ms 5212 KB Output is correct
57 Correct 16 ms 7036 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 15 ms 7260 KB Output is correct
60 Correct 3 ms 5212 KB Output is correct
61 Correct 17 ms 7060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 2 ms 5096 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5004 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 4968 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 3 ms 5212 KB Output is correct
17 Correct 3 ms 5212 KB Output is correct
18 Correct 3 ms 5132 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5212 KB Output is correct
21 Correct 3 ms 5164 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 27 ms 14280 KB Output is correct
25 Correct 35 ms 14164 KB Output is correct
26 Correct 26 ms 14172 KB Output is correct
27 Correct 3 ms 4952 KB Output is correct
28 Correct 3 ms 5208 KB Output is correct
29 Correct 3 ms 4956 KB Output is correct
30 Correct 3 ms 5140 KB Output is correct
31 Correct 4 ms 5000 KB Output is correct
32 Correct 2 ms 4956 KB Output is correct
33 Correct 2 ms 4956 KB Output is correct
34 Correct 3 ms 4956 KB Output is correct
35 Correct 4 ms 4952 KB Output is correct
36 Correct 3 ms 5212 KB Output is correct
37 Correct 4 ms 5256 KB Output is correct
38 Correct 3 ms 5212 KB Output is correct
39 Correct 3 ms 5212 KB Output is correct
40 Correct 5 ms 5212 KB Output is correct
41 Correct 4 ms 5212 KB Output is correct
42 Correct 4 ms 5212 KB Output is correct
43 Correct 2 ms 5208 KB Output is correct
44 Correct 9 ms 6236 KB Output is correct
45 Correct 2 ms 5212 KB Output is correct
46 Correct 4 ms 4956 KB Output is correct
47 Correct 4 ms 5208 KB Output is correct
48 Correct 5 ms 5212 KB Output is correct
49 Correct 2 ms 4956 KB Output is correct
50 Correct 3 ms 5136 KB Output is correct
51 Correct 3 ms 4956 KB Output is correct
52 Correct 4 ms 4956 KB Output is correct
53 Correct 4 ms 5212 KB Output is correct
54 Correct 3 ms 5212 KB Output is correct
55 Correct 3 ms 5212 KB Output is correct
56 Correct 3 ms 5212 KB Output is correct
57 Correct 4 ms 5212 KB Output is correct
58 Correct 3 ms 5212 KB Output is correct
59 Correct 3 ms 5212 KB Output is correct
60 Correct 16 ms 7036 KB Output is correct
61 Correct 3 ms 5212 KB Output is correct
62 Correct 15 ms 7260 KB Output is correct
63 Correct 3 ms 5212 KB Output is correct
64 Correct 17 ms 7060 KB Output is correct
65 Correct 64 ms 5460 KB Output is correct
66 Correct 9 ms 5212 KB Output is correct
67 Correct 40 ms 5316 KB Output is correct
68 Correct 15 ms 5212 KB Output is correct
69 Correct 41 ms 5212 KB Output is correct
70 Correct 62 ms 6228 KB Output is correct
71 Correct 69 ms 6348 KB Output is correct
72 Correct 31 ms 6236 KB Output is correct
73 Correct 5 ms 5468 KB Output is correct
74 Correct 44 ms 6152 KB Output is correct
75 Correct 44 ms 5968 KB Output is correct
76 Correct 27 ms 13596 KB Output is correct
77 Correct 28 ms 14672 KB Output is correct
78 Correct 44 ms 15996 KB Output is correct
79 Correct 132 ms 5580 KB Output is correct
80 Correct 135 ms 5520 KB Output is correct
81 Correct 115 ms 5424 KB Output is correct
82 Correct 123 ms 5388 KB Output is correct
83 Correct 140 ms 5456 KB Output is correct
84 Correct 131 ms 6484 KB Output is correct
85 Correct 129 ms 6484 KB Output is correct
86 Correct 129 ms 6400 KB Output is correct
87 Correct 151 ms 6484 KB Output is correct
88 Correct 135 ms 6484 KB Output is correct
89 Correct 137 ms 6472 KB Output is correct
90 Correct 40 ms 16976 KB Output is correct
91 Correct 39 ms 16932 KB Output is correct
92 Correct 41 ms 17144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 2 ms 5096 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5004 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 4968 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 3 ms 5212 KB Output is correct
17 Correct 3 ms 5212 KB Output is correct
18 Correct 3 ms 5132 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5212 KB Output is correct
21 Correct 3 ms 5164 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 27 ms 14280 KB Output is correct
25 Correct 35 ms 14164 KB Output is correct
26 Correct 26 ms 14172 KB Output is correct
27 Correct 5 ms 8028 KB Output is correct
28 Correct 5 ms 8024 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 4 ms 5212 KB Output is correct
31 Correct 4 ms 5256 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 537 ms 9932 KB Output is correct
34 Correct 535 ms 9944 KB Output is correct
35 Correct 568 ms 10064 KB Output is correct
36 Correct 602 ms 10064 KB Output is correct
37 Correct 604 ms 10072 KB Output is correct
38 Correct 582 ms 10068 KB Output is correct
39 Correct 33 ms 14676 KB Output is correct
40 Correct 39 ms 14916 KB Output is correct
41 Correct 30 ms 14672 KB Output is correct
42 Correct 3 ms 4952 KB Output is correct
43 Correct 3 ms 5208 KB Output is correct
44 Correct 3 ms 4956 KB Output is correct
45 Correct 3 ms 5140 KB Output is correct
46 Correct 4 ms 5000 KB Output is correct
47 Correct 2 ms 4956 KB Output is correct
48 Correct 2 ms 4956 KB Output is correct
49 Correct 3 ms 4956 KB Output is correct
50 Correct 4 ms 4952 KB Output is correct
51 Correct 3 ms 5212 KB Output is correct
52 Correct 4 ms 5256 KB Output is correct
53 Correct 3 ms 5212 KB Output is correct
54 Correct 3 ms 5212 KB Output is correct
55 Correct 5 ms 5212 KB Output is correct
56 Correct 4 ms 5212 KB Output is correct
57 Correct 4 ms 5212 KB Output is correct
58 Correct 2 ms 5208 KB Output is correct
59 Correct 9 ms 6236 KB Output is correct
60 Correct 2 ms 5212 KB Output is correct
61 Correct 4 ms 4956 KB Output is correct
62 Correct 4 ms 5208 KB Output is correct
63 Correct 5 ms 5212 KB Output is correct
64 Correct 2 ms 4956 KB Output is correct
65 Correct 3 ms 5136 KB Output is correct
66 Correct 3 ms 4956 KB Output is correct
67 Correct 4 ms 4956 KB Output is correct
68 Correct 4 ms 5212 KB Output is correct
69 Correct 3 ms 5212 KB Output is correct
70 Correct 3 ms 5212 KB Output is correct
71 Correct 3 ms 5212 KB Output is correct
72 Correct 4 ms 5212 KB Output is correct
73 Correct 3 ms 5212 KB Output is correct
74 Correct 3 ms 5212 KB Output is correct
75 Correct 16 ms 7036 KB Output is correct
76 Correct 3 ms 5212 KB Output is correct
77 Correct 15 ms 7260 KB Output is correct
78 Correct 3 ms 5212 KB Output is correct
79 Correct 17 ms 7060 KB Output is correct
80 Correct 64 ms 5460 KB Output is correct
81 Correct 9 ms 5212 KB Output is correct
82 Correct 40 ms 5316 KB Output is correct
83 Correct 15 ms 5212 KB Output is correct
84 Correct 41 ms 5212 KB Output is correct
85 Correct 62 ms 6228 KB Output is correct
86 Correct 69 ms 6348 KB Output is correct
87 Correct 31 ms 6236 KB Output is correct
88 Correct 5 ms 5468 KB Output is correct
89 Correct 44 ms 6152 KB Output is correct
90 Correct 44 ms 5968 KB Output is correct
91 Correct 27 ms 13596 KB Output is correct
92 Correct 28 ms 14672 KB Output is correct
93 Correct 44 ms 15996 KB Output is correct
94 Correct 132 ms 5580 KB Output is correct
95 Correct 135 ms 5520 KB Output is correct
96 Correct 115 ms 5424 KB Output is correct
97 Correct 123 ms 5388 KB Output is correct
98 Correct 140 ms 5456 KB Output is correct
99 Correct 131 ms 6484 KB Output is correct
100 Correct 129 ms 6484 KB Output is correct
101 Correct 129 ms 6400 KB Output is correct
102 Correct 151 ms 6484 KB Output is correct
103 Correct 135 ms 6484 KB Output is correct
104 Correct 137 ms 6472 KB Output is correct
105 Correct 40 ms 16976 KB Output is correct
106 Correct 39 ms 16932 KB Output is correct
107 Correct 41 ms 17144 KB Output is correct
108 Correct 5 ms 8028 KB Output is correct
109 Execution timed out 1587 ms 10400 KB Time limit exceeded
110 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 2 ms 4952 KB Output is correct
4 Correct 3 ms 4952 KB Output is correct
5 Correct 2 ms 5096 KB Output is correct
6 Correct 2 ms 4956 KB Output is correct
7 Correct 3 ms 4956 KB Output is correct
8 Correct 3 ms 5004 KB Output is correct
9 Correct 2 ms 5212 KB Output is correct
10 Correct 2 ms 5212 KB Output is correct
11 Correct 2 ms 4968 KB Output is correct
12 Correct 2 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 2 ms 4956 KB Output is correct
15 Correct 3 ms 5212 KB Output is correct
16 Correct 3 ms 5212 KB Output is correct
17 Correct 3 ms 5212 KB Output is correct
18 Correct 3 ms 5132 KB Output is correct
19 Correct 3 ms 5208 KB Output is correct
20 Correct 3 ms 5212 KB Output is correct
21 Correct 3 ms 5164 KB Output is correct
22 Correct 2 ms 5212 KB Output is correct
23 Correct 3 ms 5212 KB Output is correct
24 Correct 27 ms 14280 KB Output is correct
25 Correct 35 ms 14164 KB Output is correct
26 Correct 26 ms 14172 KB Output is correct
27 Correct 5 ms 8028 KB Output is correct
28 Correct 5 ms 8024 KB Output is correct
29 Correct 3 ms 5212 KB Output is correct
30 Correct 4 ms 5212 KB Output is correct
31 Correct 4 ms 5256 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 537 ms 9932 KB Output is correct
34 Correct 535 ms 9944 KB Output is correct
35 Correct 568 ms 10064 KB Output is correct
36 Correct 602 ms 10064 KB Output is correct
37 Correct 604 ms 10072 KB Output is correct
38 Correct 582 ms 10068 KB Output is correct
39 Correct 33 ms 14676 KB Output is correct
40 Correct 39 ms 14916 KB Output is correct
41 Correct 30 ms 14672 KB Output is correct
42 Correct 18 ms 19036 KB Output is correct
43 Correct 18 ms 13912 KB Output is correct
44 Correct 8 ms 6440 KB Output is correct
45 Correct 11 ms 6040 KB Output is correct
46 Correct 11 ms 5980 KB Output is correct
47 Correct 7 ms 6492 KB Output is correct
48 Execution timed out 1559 ms 20220 KB Time limit exceeded
49 Halted 0 ms 0 KB -