#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5;
const int snax = 1e4;
vector<int> col_to_wall[nax], cand[nax];
vector<bitset<nax/2>>is(snax);
bool good[nax];
bool on[nax];
int minimumInstructions(
int N, int M, int K, vector<int> C,
vector<int> A, vector<vector<int>> B) {
for(int i=0; i<N; ++i) {
col_to_wall[C[i]].push_back(i);
}
for(int i=0; i<M; ++i) {
for(int j=0; j<A[i]; ++j) {
for(int x : col_to_wall[B[i][j]]) {
cand[x].push_back(i);
is[x][i] = 1;
}
}
}
int prev_succ = -1;
for(int i=0; i<=N-M; ++i) {
int cur_succ = -1;
for(int j : cand[i]) {
int pre_tag = (j-1+M)%M;
bool yasss = true;
if(pre_tag==prev_succ) {
if(i+M-1<snax) {
if(is[i+M-1][pre_tag]) {
cur_succ = j;
break;
} else continue;
} else {
if(binary_search(cand[i+M-1].begin(), cand[i+M-1].end(), pre_tag)) {
cur_succ = j;
break;
} else continue;
}
} else if(on[pre_tag]) {
continue;
}
for(int l=1, cr=j+1; l<M; ++l, ++cr) {
if(cr==M) cr = 0;
if(i+l<snax) yasss &= is[i+l][cr];
else yasss &= binary_search(cand[i+l].begin(), cand[i+l].end(), cr);
if(!yasss) break;
}
if(yasss) {
cur_succ = j;
break;
}
}
if(i) {
for(int x : cand[i-1]) {
if(x==prev_succ) break;
on[x] = 0;
}
}
for(int x : cand[i]) {
if(x==cur_succ) break;
on[x] = 1;
}
prev_succ = cur_succ;
if(cur_succ!=-1) {
good[i] = 1;
}
}
if(!good[0]) return -1;
int last = 0, pending = -1;
int ans = 1;
for(int i=1; i<N; ++i) {
if(good[i]) {
pending = i;
}
if(last+M==i) {
if(pending==-1) return -1;
last = pending;
pending = -1;
++ans;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
66132 KB |
Output is correct |
2 |
Correct |
28 ms |
66132 KB |
Output is correct |
3 |
Correct |
28 ms |
66196 KB |
Output is correct |
4 |
Correct |
27 ms |
66168 KB |
Output is correct |
5 |
Correct |
27 ms |
66152 KB |
Output is correct |
6 |
Correct |
27 ms |
66220 KB |
Output is correct |
7 |
Correct |
26 ms |
66236 KB |
Output is correct |
8 |
Correct |
26 ms |
66132 KB |
Output is correct |
9 |
Correct |
28 ms |
66260 KB |
Output is correct |
10 |
Correct |
28 ms |
66252 KB |
Output is correct |
11 |
Correct |
29 ms |
66164 KB |
Output is correct |
12 |
Correct |
28 ms |
66236 KB |
Output is correct |
13 |
Correct |
28 ms |
66248 KB |
Output is correct |
14 |
Correct |
28 ms |
66260 KB |
Output is correct |
15 |
Correct |
28 ms |
66252 KB |
Output is correct |
16 |
Correct |
28 ms |
66184 KB |
Output is correct |
17 |
Correct |
27 ms |
66228 KB |
Output is correct |
18 |
Correct |
28 ms |
66252 KB |
Output is correct |
19 |
Correct |
29 ms |
66184 KB |
Output is correct |
20 |
Correct |
27 ms |
66252 KB |
Output is correct |
21 |
Correct |
28 ms |
66260 KB |
Output is correct |
22 |
Correct |
38 ms |
67012 KB |
Output is correct |
23 |
Correct |
38 ms |
66948 KB |
Output is correct |
24 |
Correct |
39 ms |
67028 KB |
Output is correct |
25 |
Runtime error |
91 ms |
135064 KB |
Execution killed with signal 11 |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
66132 KB |
Output is correct |
2 |
Correct |
28 ms |
66132 KB |
Output is correct |
3 |
Correct |
28 ms |
66196 KB |
Output is correct |
4 |
Correct |
27 ms |
66168 KB |
Output is correct |
5 |
Correct |
27 ms |
66152 KB |
Output is correct |
6 |
Correct |
27 ms |
66220 KB |
Output is correct |
7 |
Correct |
26 ms |
66236 KB |
Output is correct |
8 |
Correct |
26 ms |
66132 KB |
Output is correct |
9 |
Correct |
28 ms |
66260 KB |
Output is correct |
10 |
Correct |
28 ms |
66252 KB |
Output is correct |
11 |
Correct |
29 ms |
66164 KB |
Output is correct |
12 |
Correct |
28 ms |
66236 KB |
Output is correct |
13 |
Correct |
28 ms |
66248 KB |
Output is correct |
14 |
Correct |
28 ms |
66260 KB |
Output is correct |
15 |
Correct |
28 ms |
66252 KB |
Output is correct |
16 |
Correct |
28 ms |
66184 KB |
Output is correct |
17 |
Correct |
27 ms |
66228 KB |
Output is correct |
18 |
Correct |
28 ms |
66252 KB |
Output is correct |
19 |
Correct |
29 ms |
66184 KB |
Output is correct |
20 |
Correct |
27 ms |
66252 KB |
Output is correct |
21 |
Correct |
28 ms |
66260 KB |
Output is correct |
22 |
Correct |
33 ms |
66124 KB |
Output is correct |
23 |
Correct |
29 ms |
66120 KB |
Output is correct |
24 |
Correct |
29 ms |
66124 KB |
Output is correct |
25 |
Correct |
29 ms |
66148 KB |
Output is correct |
26 |
Correct |
31 ms |
66196 KB |
Output is correct |
27 |
Correct |
29 ms |
66124 KB |
Output is correct |
28 |
Correct |
29 ms |
66152 KB |
Output is correct |
29 |
Correct |
28 ms |
66200 KB |
Output is correct |
30 |
Correct |
29 ms |
66304 KB |
Output is correct |
31 |
Correct |
29 ms |
66256 KB |
Output is correct |
32 |
Correct |
29 ms |
66260 KB |
Output is correct |
33 |
Correct |
28 ms |
66256 KB |
Output is correct |
34 |
Correct |
29 ms |
66200 KB |
Output is correct |
35 |
Correct |
28 ms |
66240 KB |
Output is correct |
36 |
Correct |
29 ms |
66264 KB |
Output is correct |
37 |
Correct |
28 ms |
66212 KB |
Output is correct |
38 |
Correct |
29 ms |
66232 KB |
Output is correct |
39 |
Correct |
29 ms |
66152 KB |
Output is correct |
40 |
Correct |
29 ms |
66160 KB |
Output is correct |
41 |
Correct |
28 ms |
66140 KB |
Output is correct |
42 |
Correct |
27 ms |
66228 KB |
Output is correct |
43 |
Correct |
33 ms |
66220 KB |
Output is correct |
44 |
Correct |
29 ms |
66184 KB |
Output is correct |
45 |
Correct |
29 ms |
66276 KB |
Output is correct |
46 |
Correct |
29 ms |
66196 KB |
Output is correct |
47 |
Correct |
30 ms |
66236 KB |
Output is correct |
48 |
Correct |
29 ms |
66216 KB |
Output is correct |
49 |
Correct |
29 ms |
66252 KB |
Output is correct |
50 |
Correct |
29 ms |
66260 KB |
Output is correct |
51 |
Correct |
29 ms |
66240 KB |
Output is correct |
52 |
Correct |
29 ms |
66260 KB |
Output is correct |
53 |
Correct |
30 ms |
66268 KB |
Output is correct |
54 |
Correct |
29 ms |
66300 KB |
Output is correct |
55 |
Correct |
29 ms |
66260 KB |
Output is correct |
56 |
Correct |
29 ms |
66216 KB |
Output is correct |
57 |
Correct |
29 ms |
66172 KB |
Output is correct |
58 |
Correct |
30 ms |
66124 KB |
Output is correct |
59 |
Correct |
29 ms |
66260 KB |
Output is correct |
60 |
Correct |
28 ms |
66152 KB |
Output is correct |
61 |
Correct |
33 ms |
66204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
66124 KB |
Output is correct |
2 |
Correct |
29 ms |
66120 KB |
Output is correct |
3 |
Correct |
27 ms |
66132 KB |
Output is correct |
4 |
Correct |
28 ms |
66132 KB |
Output is correct |
5 |
Correct |
28 ms |
66196 KB |
Output is correct |
6 |
Correct |
27 ms |
66168 KB |
Output is correct |
7 |
Correct |
27 ms |
66152 KB |
Output is correct |
8 |
Correct |
27 ms |
66220 KB |
Output is correct |
9 |
Correct |
26 ms |
66236 KB |
Output is correct |
10 |
Correct |
26 ms |
66132 KB |
Output is correct |
11 |
Correct |
28 ms |
66260 KB |
Output is correct |
12 |
Correct |
28 ms |
66252 KB |
Output is correct |
13 |
Correct |
29 ms |
66164 KB |
Output is correct |
14 |
Correct |
28 ms |
66236 KB |
Output is correct |
15 |
Correct |
28 ms |
66248 KB |
Output is correct |
16 |
Correct |
28 ms |
66260 KB |
Output is correct |
17 |
Correct |
28 ms |
66252 KB |
Output is correct |
18 |
Correct |
28 ms |
66184 KB |
Output is correct |
19 |
Correct |
27 ms |
66228 KB |
Output is correct |
20 |
Correct |
28 ms |
66252 KB |
Output is correct |
21 |
Correct |
29 ms |
66184 KB |
Output is correct |
22 |
Correct |
27 ms |
66252 KB |
Output is correct |
23 |
Correct |
28 ms |
66260 KB |
Output is correct |
24 |
Correct |
38 ms |
67012 KB |
Output is correct |
25 |
Correct |
38 ms |
66948 KB |
Output is correct |
26 |
Correct |
39 ms |
67028 KB |
Output is correct |
27 |
Correct |
29 ms |
66124 KB |
Output is correct |
28 |
Correct |
29 ms |
66148 KB |
Output is correct |
29 |
Correct |
31 ms |
66196 KB |
Output is correct |
30 |
Correct |
29 ms |
66124 KB |
Output is correct |
31 |
Correct |
29 ms |
66152 KB |
Output is correct |
32 |
Correct |
28 ms |
66200 KB |
Output is correct |
33 |
Correct |
29 ms |
66304 KB |
Output is correct |
34 |
Correct |
29 ms |
66256 KB |
Output is correct |
35 |
Correct |
29 ms |
66260 KB |
Output is correct |
36 |
Correct |
28 ms |
66256 KB |
Output is correct |
37 |
Correct |
29 ms |
66200 KB |
Output is correct |
38 |
Correct |
28 ms |
66240 KB |
Output is correct |
39 |
Correct |
29 ms |
66264 KB |
Output is correct |
40 |
Correct |
28 ms |
66212 KB |
Output is correct |
41 |
Correct |
29 ms |
66232 KB |
Output is correct |
42 |
Correct |
29 ms |
66152 KB |
Output is correct |
43 |
Correct |
29 ms |
66160 KB |
Output is correct |
44 |
Correct |
28 ms |
66140 KB |
Output is correct |
45 |
Correct |
27 ms |
66228 KB |
Output is correct |
46 |
Correct |
33 ms |
66220 KB |
Output is correct |
47 |
Correct |
29 ms |
66184 KB |
Output is correct |
48 |
Correct |
29 ms |
66276 KB |
Output is correct |
49 |
Correct |
29 ms |
66196 KB |
Output is correct |
50 |
Correct |
30 ms |
66236 KB |
Output is correct |
51 |
Correct |
29 ms |
66216 KB |
Output is correct |
52 |
Correct |
29 ms |
66252 KB |
Output is correct |
53 |
Correct |
29 ms |
66260 KB |
Output is correct |
54 |
Correct |
29 ms |
66240 KB |
Output is correct |
55 |
Correct |
29 ms |
66260 KB |
Output is correct |
56 |
Correct |
30 ms |
66268 KB |
Output is correct |
57 |
Correct |
29 ms |
66300 KB |
Output is correct |
58 |
Correct |
29 ms |
66260 KB |
Output is correct |
59 |
Correct |
29 ms |
66216 KB |
Output is correct |
60 |
Correct |
29 ms |
66172 KB |
Output is correct |
61 |
Correct |
30 ms |
66124 KB |
Output is correct |
62 |
Correct |
29 ms |
66260 KB |
Output is correct |
63 |
Correct |
28 ms |
66152 KB |
Output is correct |
64 |
Correct |
33 ms |
66204 KB |
Output is correct |
65 |
Correct |
31 ms |
66400 KB |
Output is correct |
66 |
Correct |
29 ms |
66380 KB |
Output is correct |
67 |
Correct |
31 ms |
66416 KB |
Output is correct |
68 |
Correct |
30 ms |
66468 KB |
Output is correct |
69 |
Correct |
32 ms |
66468 KB |
Output is correct |
70 |
Correct |
31 ms |
66392 KB |
Output is correct |
71 |
Correct |
31 ms |
66380 KB |
Output is correct |
72 |
Correct |
31 ms |
66388 KB |
Output is correct |
73 |
Correct |
30 ms |
66252 KB |
Output is correct |
74 |
Correct |
32 ms |
66388 KB |
Output is correct |
75 |
Correct |
33 ms |
66340 KB |
Output is correct |
76 |
Correct |
39 ms |
67048 KB |
Output is correct |
77 |
Correct |
40 ms |
67136 KB |
Output is correct |
78 |
Correct |
43 ms |
67348 KB |
Output is correct |
79 |
Correct |
31 ms |
66740 KB |
Output is correct |
80 |
Correct |
29 ms |
66764 KB |
Output is correct |
81 |
Correct |
37 ms |
66792 KB |
Output is correct |
82 |
Correct |
30 ms |
66716 KB |
Output is correct |
83 |
Correct |
32 ms |
66772 KB |
Output is correct |
84 |
Correct |
32 ms |
66368 KB |
Output is correct |
85 |
Correct |
30 ms |
66360 KB |
Output is correct |
86 |
Correct |
31 ms |
66380 KB |
Output is correct |
87 |
Correct |
32 ms |
66392 KB |
Output is correct |
88 |
Correct |
32 ms |
66388 KB |
Output is correct |
89 |
Correct |
30 ms |
66424 KB |
Output is correct |
90 |
Correct |
44 ms |
67436 KB |
Output is correct |
91 |
Correct |
43 ms |
67456 KB |
Output is correct |
92 |
Correct |
43 ms |
67432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
66124 KB |
Output is correct |
2 |
Correct |
29 ms |
66120 KB |
Output is correct |
3 |
Correct |
27 ms |
66132 KB |
Output is correct |
4 |
Correct |
28 ms |
66132 KB |
Output is correct |
5 |
Correct |
28 ms |
66196 KB |
Output is correct |
6 |
Correct |
27 ms |
66168 KB |
Output is correct |
7 |
Correct |
27 ms |
66152 KB |
Output is correct |
8 |
Correct |
27 ms |
66220 KB |
Output is correct |
9 |
Correct |
26 ms |
66236 KB |
Output is correct |
10 |
Correct |
26 ms |
66132 KB |
Output is correct |
11 |
Correct |
28 ms |
66260 KB |
Output is correct |
12 |
Correct |
28 ms |
66252 KB |
Output is correct |
13 |
Correct |
29 ms |
66164 KB |
Output is correct |
14 |
Correct |
28 ms |
66236 KB |
Output is correct |
15 |
Correct |
28 ms |
66248 KB |
Output is correct |
16 |
Correct |
28 ms |
66260 KB |
Output is correct |
17 |
Correct |
28 ms |
66252 KB |
Output is correct |
18 |
Correct |
28 ms |
66184 KB |
Output is correct |
19 |
Correct |
27 ms |
66228 KB |
Output is correct |
20 |
Correct |
28 ms |
66252 KB |
Output is correct |
21 |
Correct |
29 ms |
66184 KB |
Output is correct |
22 |
Correct |
27 ms |
66252 KB |
Output is correct |
23 |
Correct |
28 ms |
66260 KB |
Output is correct |
24 |
Correct |
38 ms |
67012 KB |
Output is correct |
25 |
Correct |
38 ms |
66948 KB |
Output is correct |
26 |
Correct |
39 ms |
67028 KB |
Output is correct |
27 |
Runtime error |
91 ms |
135064 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
66124 KB |
Output is correct |
2 |
Correct |
29 ms |
66120 KB |
Output is correct |
3 |
Correct |
27 ms |
66132 KB |
Output is correct |
4 |
Correct |
28 ms |
66132 KB |
Output is correct |
5 |
Correct |
28 ms |
66196 KB |
Output is correct |
6 |
Correct |
27 ms |
66168 KB |
Output is correct |
7 |
Correct |
27 ms |
66152 KB |
Output is correct |
8 |
Correct |
27 ms |
66220 KB |
Output is correct |
9 |
Correct |
26 ms |
66236 KB |
Output is correct |
10 |
Correct |
26 ms |
66132 KB |
Output is correct |
11 |
Correct |
28 ms |
66260 KB |
Output is correct |
12 |
Correct |
28 ms |
66252 KB |
Output is correct |
13 |
Correct |
29 ms |
66164 KB |
Output is correct |
14 |
Correct |
28 ms |
66236 KB |
Output is correct |
15 |
Correct |
28 ms |
66248 KB |
Output is correct |
16 |
Correct |
28 ms |
66260 KB |
Output is correct |
17 |
Correct |
28 ms |
66252 KB |
Output is correct |
18 |
Correct |
28 ms |
66184 KB |
Output is correct |
19 |
Correct |
27 ms |
66228 KB |
Output is correct |
20 |
Correct |
28 ms |
66252 KB |
Output is correct |
21 |
Correct |
29 ms |
66184 KB |
Output is correct |
22 |
Correct |
27 ms |
66252 KB |
Output is correct |
23 |
Correct |
28 ms |
66260 KB |
Output is correct |
24 |
Correct |
38 ms |
67012 KB |
Output is correct |
25 |
Correct |
38 ms |
66948 KB |
Output is correct |
26 |
Correct |
39 ms |
67028 KB |
Output is correct |
27 |
Runtime error |
91 ms |
135064 KB |
Execution killed with signal 11 |
28 |
Halted |
0 ms |
0 KB |
- |