#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, m, k;
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
vector<int> a, c;
vector<vector<int>> b;
n = N;
m = M;
k = K;
c = C;
a = A;
b = B;
assert((int)c.size() == n);
assert((int)a.size() == m);
assert((int)b.size() == m);
for (int i = 0; i < m; i++) {
assert((int)b[i].size() == a[i]);
}
vector<int> f(k, 0);
for (int i = 0; i < m; i++) {
for (auto& it : b[i]) {
f[it]++;
}
}
vector<int> has(k, -1);
vector<int> need(n, 0);
for (int i = 0; i < m; i++) {
for (auto& it : b[i]) {
has[it] = i;
}
}
for (int i = 0; i < n; i++) {
if (f[c[i]] == 0) {
return -1;
}
need[i] = has[c[i]];
}
int sol = 0, pos = need[0], cur = 1;
for (int i = 1; i < n; i++) {
bool ok = false;
ok |= (need[i] == (pos + 1) % m);
if (!ok) {
if (cur < m) {
return -1;
}
sol += (cur + m - 1) / m;
cur = 0;
}
cur++;
pos = need[i];
}
if (cur < m) {
return -1;
}
sol += (cur + m - 1) / m;
return sol;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
1 ms |
1112 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
1112 KB |
Output is correct |
18 |
Correct |
1 ms |
1112 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Correct |
8 ms |
2396 KB |
Output is correct |
23 |
Correct |
8 ms |
2392 KB |
Output is correct |
24 |
Correct |
8 ms |
2392 KB |
Output is correct |
25 |
Correct |
2 ms |
600 KB |
Output is correct |
26 |
Correct |
2 ms |
600 KB |
Output is correct |
27 |
Correct |
2 ms |
600 KB |
Output is correct |
28 |
Correct |
2 ms |
600 KB |
Output is correct |
29 |
Correct |
2 ms |
600 KB |
Output is correct |
30 |
Correct |
2 ms |
600 KB |
Output is correct |
31 |
Correct |
4 ms |
1880 KB |
Output is correct |
32 |
Correct |
4 ms |
1880 KB |
Output is correct |
33 |
Correct |
5 ms |
1880 KB |
Output is correct |
34 |
Correct |
4 ms |
1880 KB |
Output is correct |
35 |
Correct |
4 ms |
1880 KB |
Output is correct |
36 |
Correct |
4 ms |
1880 KB |
Output is correct |
37 |
Correct |
11 ms |
2904 KB |
Output is correct |
38 |
Correct |
11 ms |
2904 KB |
Output is correct |
39 |
Correct |
10 ms |
2904 KB |
Output is correct |
40 |
Correct |
7 ms |
1628 KB |
Output is correct |
41 |
Correct |
4 ms |
1112 KB |
Output is correct |
42 |
Correct |
7 ms |
1880 KB |
Output is correct |
43 |
Correct |
5 ms |
1368 KB |
Output is correct |
44 |
Correct |
4 ms |
1368 KB |
Output is correct |
45 |
Correct |
7 ms |
1884 KB |
Output is correct |
46 |
Correct |
26 ms |
11096 KB |
Output is correct |
47 |
Correct |
16 ms |
6744 KB |
Output is correct |
48 |
Correct |
21 ms |
10576 KB |
Output is correct |
49 |
Correct |
23 ms |
9816 KB |
Output is correct |
50 |
Correct |
23 ms |
9040 KB |
Output is correct |
51 |
Correct |
17 ms |
6488 KB |
Output is correct |
52 |
Correct |
8 ms |
2136 KB |
Output is correct |
53 |
Correct |
8 ms |
2140 KB |
Output is correct |
54 |
Correct |
7 ms |
2136 KB |
Output is correct |
55 |
Correct |
9 ms |
2140 KB |
Output is correct |
56 |
Correct |
7 ms |
2136 KB |
Output is correct |
57 |
Correct |
7 ms |
2136 KB |
Output is correct |
58 |
Correct |
30 ms |
12624 KB |
Output is correct |
59 |
Correct |
29 ms |
12624 KB |
Output is correct |
60 |
Correct |
35 ms |
12620 KB |
Output is correct |
61 |
Correct |
30 ms |
12624 KB |
Output is correct |
62 |
Correct |
29 ms |
12740 KB |
Output is correct |
63 |
Correct |
28 ms |
12820 KB |
Output is correct |
64 |
Correct |
28 ms |
11436 KB |
Output is correct |
65 |
Correct |
30 ms |
11520 KB |
Output is correct |
66 |
Correct |
29 ms |
11600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 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 |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
1112 KB |
Output is correct |
14 |
Correct |
1 ms |
1112 KB |
Output is correct |
15 |
Correct |
1 ms |
1116 KB |
Output is correct |
16 |
Correct |
1 ms |
1116 KB |
Output is correct |
17 |
Correct |
1 ms |
1112 KB |
Output is correct |
18 |
Correct |
1 ms |
1112 KB |
Output is correct |
19 |
Correct |
1 ms |
1116 KB |
Output is correct |
20 |
Correct |
1 ms |
1116 KB |
Output is correct |
21 |
Correct |
1 ms |
1112 KB |
Output is correct |
22 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |