#include <bits/stdc++.h>
using namespace std;
const int inf = 1e7;
int minimumInstructions(int n, int m, int K, vector<int> c, vector<int> a, vector< vector<int> > b) {
vector<bool> can(n);
for (int i = 0; i < n; i++) {
can[i] = false;
}
vector< vector<int> > S(K);
map<int, bool> mp[m];
for (int i = 0; i < m; i++) {
for (int j = 0; j < a[i]; j++) {
mp[i][b[i][j]] = true;
S[b[i][j]].push_back(i);
}
}
for (int i = 0; i <= n - m; i++) {
for (int j = 0; j < (int)S[c[i]].size(); j++) {
int x = S[c[i]][j];
bool OK = true;
for (int k = 0; k < m; k++) {
if (!mp[(x + k) % m][c[i + k]]) {
OK = false;
}
}
if (OK) {
can[i] = true;
}
}
}
int dp[n + 1];
for (int i = 0; i <= n; i++) dp[i] = inf;
dp[0] = 0;
for (int i = 0; i < n; i++) {
if (can[i]) {
for (int j = i + 1; j <= i + m; j++) {
dp[j] = min(dp[j], dp[i] + 1);
}
}
}
int ans = dp[n];
if (dp[n] == inf) ans = -1;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2728 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2724 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2724 KB |
Output is correct |
19 |
Correct |
3 ms |
2764 KB |
Output is correct |
20 |
Correct |
3 ms |
2764 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
71 ms |
13636 KB |
Output is correct |
23 |
Correct |
70 ms |
13796 KB |
Output is correct |
24 |
Correct |
89 ms |
13816 KB |
Output is correct |
25 |
Correct |
5 ms |
460 KB |
Output is correct |
26 |
Correct |
4 ms |
460 KB |
Output is correct |
27 |
Correct |
4 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
492 KB |
Output is correct |
30 |
Correct |
5 ms |
460 KB |
Output is correct |
31 |
Correct |
1006 ms |
4988 KB |
Output is correct |
32 |
Correct |
1010 ms |
4984 KB |
Output is correct |
33 |
Correct |
1008 ms |
4980 KB |
Output is correct |
34 |
Correct |
1002 ms |
5060 KB |
Output is correct |
35 |
Correct |
1020 ms |
5060 KB |
Output is correct |
36 |
Correct |
1020 ms |
4980 KB |
Output is correct |
37 |
Execution timed out |
1594 ms |
91344 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
3 ms |
2728 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2724 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2724 KB |
Output is correct |
19 |
Correct |
3 ms |
2764 KB |
Output is correct |
20 |
Correct |
3 ms |
2764 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
204 KB |
Output is correct |
24 |
Correct |
1 ms |
204 KB |
Output is correct |
25 |
Correct |
1 ms |
204 KB |
Output is correct |
26 |
Correct |
1 ms |
204 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
2 ms |
204 KB |
Output is correct |
29 |
Correct |
2 ms |
204 KB |
Output is correct |
30 |
Correct |
2 ms |
204 KB |
Output is correct |
31 |
Correct |
1 ms |
204 KB |
Output is correct |
32 |
Correct |
4 ms |
204 KB |
Output is correct |
33 |
Correct |
3 ms |
2252 KB |
Output is correct |
34 |
Correct |
2 ms |
1868 KB |
Output is correct |
35 |
Correct |
2 ms |
1612 KB |
Output is correct |
36 |
Correct |
3 ms |
2636 KB |
Output is correct |
37 |
Correct |
2 ms |
2124 KB |
Output is correct |
38 |
Correct |
3 ms |
2340 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
2 ms |
2124 KB |
Output is correct |
41 |
Correct |
6 ms |
1100 KB |
Output is correct |
42 |
Correct |
2 ms |
2508 KB |
Output is correct |
43 |
Correct |
3 ms |
2468 KB |
Output is correct |
44 |
Correct |
1 ms |
204 KB |
Output is correct |
45 |
Correct |
4 ms |
292 KB |
Output is correct |
46 |
Correct |
7 ms |
300 KB |
Output is correct |
47 |
Correct |
4 ms |
204 KB |
Output is correct |
48 |
Correct |
7 ms |
296 KB |
Output is correct |
49 |
Correct |
8 ms |
204 KB |
Output is correct |
50 |
Correct |
3 ms |
2636 KB |
Output is correct |
51 |
Correct |
3 ms |
2636 KB |
Output is correct |
52 |
Correct |
3 ms |
2636 KB |
Output is correct |
53 |
Correct |
3 ms |
2636 KB |
Output is correct |
54 |
Correct |
3 ms |
2636 KB |
Output is correct |
55 |
Correct |
3 ms |
2636 KB |
Output is correct |
56 |
Correct |
3 ms |
2764 KB |
Output is correct |
57 |
Correct |
14 ms |
1928 KB |
Output is correct |
58 |
Correct |
3 ms |
2764 KB |
Output is correct |
59 |
Correct |
15 ms |
1940 KB |
Output is correct |
60 |
Correct |
3 ms |
2764 KB |
Output is correct |
61 |
Correct |
17 ms |
1912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2728 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2724 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
3 ms |
2724 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
71 ms |
13636 KB |
Output is correct |
25 |
Correct |
70 ms |
13796 KB |
Output is correct |
26 |
Correct |
89 ms |
13816 KB |
Output is correct |
27 |
Correct |
1 ms |
204 KB |
Output is correct |
28 |
Correct |
1 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
204 KB |
Output is correct |
30 |
Correct |
1 ms |
204 KB |
Output is correct |
31 |
Correct |
2 ms |
204 KB |
Output is correct |
32 |
Correct |
2 ms |
204 KB |
Output is correct |
33 |
Correct |
2 ms |
204 KB |
Output is correct |
34 |
Correct |
1 ms |
204 KB |
Output is correct |
35 |
Correct |
4 ms |
204 KB |
Output is correct |
36 |
Correct |
3 ms |
2252 KB |
Output is correct |
37 |
Correct |
2 ms |
1868 KB |
Output is correct |
38 |
Correct |
2 ms |
1612 KB |
Output is correct |
39 |
Correct |
3 ms |
2636 KB |
Output is correct |
40 |
Correct |
2 ms |
2124 KB |
Output is correct |
41 |
Correct |
3 ms |
2340 KB |
Output is correct |
42 |
Correct |
1 ms |
332 KB |
Output is correct |
43 |
Correct |
2 ms |
2124 KB |
Output is correct |
44 |
Correct |
6 ms |
1100 KB |
Output is correct |
45 |
Correct |
2 ms |
2508 KB |
Output is correct |
46 |
Correct |
3 ms |
2468 KB |
Output is correct |
47 |
Correct |
1 ms |
204 KB |
Output is correct |
48 |
Correct |
4 ms |
292 KB |
Output is correct |
49 |
Correct |
7 ms |
300 KB |
Output is correct |
50 |
Correct |
4 ms |
204 KB |
Output is correct |
51 |
Correct |
7 ms |
296 KB |
Output is correct |
52 |
Correct |
8 ms |
204 KB |
Output is correct |
53 |
Correct |
3 ms |
2636 KB |
Output is correct |
54 |
Correct |
3 ms |
2636 KB |
Output is correct |
55 |
Correct |
3 ms |
2636 KB |
Output is correct |
56 |
Correct |
3 ms |
2636 KB |
Output is correct |
57 |
Correct |
3 ms |
2636 KB |
Output is correct |
58 |
Correct |
3 ms |
2636 KB |
Output is correct |
59 |
Correct |
3 ms |
2764 KB |
Output is correct |
60 |
Correct |
14 ms |
1928 KB |
Output is correct |
61 |
Correct |
3 ms |
2764 KB |
Output is correct |
62 |
Correct |
15 ms |
1940 KB |
Output is correct |
63 |
Correct |
3 ms |
2764 KB |
Output is correct |
64 |
Correct |
17 ms |
1912 KB |
Output is correct |
65 |
Correct |
14 ms |
336 KB |
Output is correct |
66 |
Correct |
6 ms |
288 KB |
Output is correct |
67 |
Correct |
41 ms |
312 KB |
Output is correct |
68 |
Correct |
16 ms |
204 KB |
Output is correct |
69 |
Correct |
41 ms |
332 KB |
Output is correct |
70 |
Correct |
82 ms |
3200 KB |
Output is correct |
71 |
Correct |
95 ms |
3004 KB |
Output is correct |
72 |
Correct |
57 ms |
2676 KB |
Output is correct |
73 |
Correct |
6 ms |
2252 KB |
Output is correct |
74 |
Correct |
68 ms |
3052 KB |
Output is correct |
75 |
Correct |
50 ms |
3268 KB |
Output is correct |
76 |
Correct |
57 ms |
11288 KB |
Output is correct |
77 |
Correct |
48 ms |
11816 KB |
Output is correct |
78 |
Correct |
67 ms |
14020 KB |
Output is correct |
79 |
Correct |
69 ms |
332 KB |
Output is correct |
80 |
Correct |
100 ms |
332 KB |
Output is correct |
81 |
Correct |
91 ms |
452 KB |
Output is correct |
82 |
Correct |
88 ms |
352 KB |
Output is correct |
83 |
Correct |
105 ms |
332 KB |
Output is correct |
84 |
Correct |
137 ms |
3832 KB |
Output is correct |
85 |
Correct |
137 ms |
3824 KB |
Output is correct |
86 |
Correct |
137 ms |
3900 KB |
Output is correct |
87 |
Correct |
138 ms |
3928 KB |
Output is correct |
88 |
Correct |
143 ms |
3908 KB |
Output is correct |
89 |
Correct |
138 ms |
3892 KB |
Output is correct |
90 |
Correct |
114 ms |
17092 KB |
Output is correct |
91 |
Correct |
111 ms |
17224 KB |
Output is correct |
92 |
Correct |
113 ms |
17296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2728 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2724 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
3 ms |
2724 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
71 ms |
13636 KB |
Output is correct |
25 |
Correct |
70 ms |
13796 KB |
Output is correct |
26 |
Correct |
89 ms |
13816 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
5 ms |
460 KB |
Output is correct |
33 |
Correct |
1006 ms |
4988 KB |
Output is correct |
34 |
Correct |
1010 ms |
4984 KB |
Output is correct |
35 |
Correct |
1008 ms |
4980 KB |
Output is correct |
36 |
Correct |
1002 ms |
5060 KB |
Output is correct |
37 |
Correct |
1020 ms |
5060 KB |
Output is correct |
38 |
Correct |
1020 ms |
4980 KB |
Output is correct |
39 |
Execution timed out |
1594 ms |
91344 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
3 ms |
2636 KB |
Output is correct |
16 |
Correct |
3 ms |
2728 KB |
Output is correct |
17 |
Correct |
3 ms |
2636 KB |
Output is correct |
18 |
Correct |
3 ms |
2724 KB |
Output is correct |
19 |
Correct |
3 ms |
2636 KB |
Output is correct |
20 |
Correct |
3 ms |
2724 KB |
Output is correct |
21 |
Correct |
3 ms |
2764 KB |
Output is correct |
22 |
Correct |
3 ms |
2764 KB |
Output is correct |
23 |
Correct |
3 ms |
2764 KB |
Output is correct |
24 |
Correct |
71 ms |
13636 KB |
Output is correct |
25 |
Correct |
70 ms |
13796 KB |
Output is correct |
26 |
Correct |
89 ms |
13816 KB |
Output is correct |
27 |
Correct |
5 ms |
460 KB |
Output is correct |
28 |
Correct |
4 ms |
460 KB |
Output is correct |
29 |
Correct |
4 ms |
460 KB |
Output is correct |
30 |
Correct |
4 ms |
460 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
5 ms |
460 KB |
Output is correct |
33 |
Correct |
1006 ms |
4988 KB |
Output is correct |
34 |
Correct |
1010 ms |
4984 KB |
Output is correct |
35 |
Correct |
1008 ms |
4980 KB |
Output is correct |
36 |
Correct |
1002 ms |
5060 KB |
Output is correct |
37 |
Correct |
1020 ms |
5060 KB |
Output is correct |
38 |
Correct |
1020 ms |
4980 KB |
Output is correct |
39 |
Execution timed out |
1594 ms |
91344 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |