#include<bits/stdc++.h>
#include "paint.h"
#define MAXN 100007
using namespace std;
int n,m,k,ans;
int c[MAXN];
vector<int> cols[MAXN];
bool can[20007][2007];
int to[2][2007];
int best[MAXN],pref[MAXN];
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector< vector<int> > B) {
n=N; m=M; k=K;
for(int i=1;i<=n;i++){
c[i]=C[i-1];
}
for(int i=1;i<=m;i++){
cols[i]=B[i-1];
}
for(int i=1;i<=n;i++){
for(int f=1;f<=m;f++){
for(int s:cols[f]){
if(s==c[i])can[i][f]=true;
}
}
}
for(int i=n;i>=1;i--){
for(int f=1;f<=m;f++){
if(!can[i][f])to[i%2][f]=0;
else{
if(f<m)to[i%2][f]=to[1-i%2][f+1]+1;
else to[i%2][f]=to[1-i%2][1]+1;
}
if(to[i%2][f]>=m)best[i]=max(best[i],i+m);
}
}
for(int i=1;i<=n;i++){
pref[i]=max(pref[i-1],best[i]);
}
int pos=1;
while(pos<=n){
if(pref[pos]<=pos)return -1;
pos=pref[pos];
ans++;
}
return ans;
}
/*
int main(){
//cout<<minimumInstructions(8, 3, 5, {3, 3, 1, 3, 4, 4, 2, 2}, {3, 2, 2}, {{0, 1, 2}, {2, 3}, {3, 4}});
cout<<minimumInstructions(5, 4, 4, {1, 0, 1, 2, 2}, {2, 1, 1, 1}, {{0, 1}, {1}, {2}, {3}});
return 0;
}
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5720 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5796 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5724 KB |
Output is correct |
17 |
Correct |
1 ms |
5724 KB |
Output is correct |
18 |
Correct |
1 ms |
5724 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
1 ms |
5724 KB |
Output is correct |
22 |
Correct |
49 ms |
6944 KB |
Output is correct |
23 |
Correct |
51 ms |
6748 KB |
Output is correct |
24 |
Correct |
48 ms |
6744 KB |
Output is correct |
25 |
Correct |
5 ms |
42844 KB |
Output is correct |
26 |
Correct |
5 ms |
42844 KB |
Output is correct |
27 |
Correct |
5 ms |
42844 KB |
Output is correct |
28 |
Correct |
5 ms |
42844 KB |
Output is correct |
29 |
Correct |
5 ms |
42844 KB |
Output is correct |
30 |
Correct |
5 ms |
42844 KB |
Output is correct |
31 |
Correct |
368 ms |
43348 KB |
Output is correct |
32 |
Correct |
361 ms |
43344 KB |
Output is correct |
33 |
Correct |
348 ms |
43248 KB |
Output is correct |
34 |
Correct |
353 ms |
43252 KB |
Output is correct |
35 |
Correct |
374 ms |
43240 KB |
Output is correct |
36 |
Correct |
348 ms |
43256 KB |
Output is correct |
37 |
Execution timed out |
1555 ms |
37972 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5724 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5720 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5724 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5796 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5724 KB |
Output is correct |
17 |
Correct |
1 ms |
5724 KB |
Output is correct |
18 |
Correct |
1 ms |
5724 KB |
Output is correct |
19 |
Correct |
2 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
1 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5976 KB |
Output is correct |
23 |
Correct |
1 ms |
5724 KB |
Output is correct |
24 |
Correct |
1 ms |
5548 KB |
Output is correct |
25 |
Correct |
1 ms |
5724 KB |
Output is correct |
26 |
Correct |
1 ms |
5724 KB |
Output is correct |
27 |
Correct |
1 ms |
5724 KB |
Output is correct |
28 |
Correct |
1 ms |
5724 KB |
Output is correct |
29 |
Correct |
1 ms |
5724 KB |
Output is correct |
30 |
Correct |
1 ms |
5724 KB |
Output is correct |
31 |
Correct |
1 ms |
5724 KB |
Output is correct |
32 |
Correct |
1 ms |
5724 KB |
Output is correct |
33 |
Correct |
1 ms |
5724 KB |
Output is correct |
34 |
Correct |
1 ms |
5724 KB |
Output is correct |
35 |
Correct |
1 ms |
5724 KB |
Output is correct |
36 |
Correct |
1 ms |
5724 KB |
Output is correct |
37 |
Correct |
1 ms |
5724 KB |
Output is correct |
38 |
Correct |
1 ms |
5724 KB |
Output is correct |
39 |
Correct |
1 ms |
5724 KB |
Output is correct |
40 |
Correct |
1 ms |
5724 KB |
Output is correct |
41 |
Correct |
1 ms |
5724 KB |
Output is correct |
42 |
Correct |
1 ms |
5724 KB |
Output is correct |
43 |
Correct |
1 ms |
5724 KB |
Output is correct |
44 |
Correct |
1 ms |
5724 KB |
Output is correct |
45 |
Correct |
1 ms |
5724 KB |
Output is correct |
46 |
Correct |
1 ms |
5724 KB |
Output is correct |
47 |
Correct |
2 ms |
5724 KB |
Output is correct |
48 |
Correct |
1 ms |
5724 KB |
Output is correct |
49 |
Correct |
1 ms |
5724 KB |
Output is correct |
50 |
Correct |
1 ms |
5724 KB |
Output is correct |
51 |
Correct |
2 ms |
5724 KB |
Output is correct |
52 |
Correct |
2 ms |
5720 KB |
Output is correct |
53 |
Correct |
1 ms |
5724 KB |
Output is correct |
54 |
Correct |
1 ms |
5772 KB |
Output is correct |
55 |
Correct |
2 ms |
5724 KB |
Output is correct |
56 |
Correct |
1 ms |
5724 KB |
Output is correct |
57 |
Correct |
1 ms |
5724 KB |
Output is correct |
58 |
Correct |
1 ms |
5724 KB |
Output is correct |
59 |
Correct |
1 ms |
5724 KB |
Output is correct |
60 |
Correct |
1 ms |
5724 KB |
Output is correct |
61 |
Correct |
1 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5976 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5720 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5796 KB |
Output is correct |
17 |
Correct |
1 ms |
5724 KB |
Output is correct |
18 |
Correct |
1 ms |
5724 KB |
Output is correct |
19 |
Correct |
1 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5724 KB |
Output is correct |
23 |
Correct |
1 ms |
5724 KB |
Output is correct |
24 |
Correct |
49 ms |
6944 KB |
Output is correct |
25 |
Correct |
51 ms |
6748 KB |
Output is correct |
26 |
Correct |
48 ms |
6744 KB |
Output is correct |
27 |
Correct |
1 ms |
5548 KB |
Output is correct |
28 |
Correct |
1 ms |
5724 KB |
Output is correct |
29 |
Correct |
1 ms |
5724 KB |
Output is correct |
30 |
Correct |
1 ms |
5724 KB |
Output is correct |
31 |
Correct |
1 ms |
5724 KB |
Output is correct |
32 |
Correct |
1 ms |
5724 KB |
Output is correct |
33 |
Correct |
1 ms |
5724 KB |
Output is correct |
34 |
Correct |
1 ms |
5724 KB |
Output is correct |
35 |
Correct |
1 ms |
5724 KB |
Output is correct |
36 |
Correct |
1 ms |
5724 KB |
Output is correct |
37 |
Correct |
1 ms |
5724 KB |
Output is correct |
38 |
Correct |
1 ms |
5724 KB |
Output is correct |
39 |
Correct |
1 ms |
5724 KB |
Output is correct |
40 |
Correct |
1 ms |
5724 KB |
Output is correct |
41 |
Correct |
1 ms |
5724 KB |
Output is correct |
42 |
Correct |
1 ms |
5724 KB |
Output is correct |
43 |
Correct |
1 ms |
5724 KB |
Output is correct |
44 |
Correct |
1 ms |
5724 KB |
Output is correct |
45 |
Correct |
1 ms |
5724 KB |
Output is correct |
46 |
Correct |
1 ms |
5724 KB |
Output is correct |
47 |
Correct |
1 ms |
5724 KB |
Output is correct |
48 |
Correct |
1 ms |
5724 KB |
Output is correct |
49 |
Correct |
1 ms |
5724 KB |
Output is correct |
50 |
Correct |
2 ms |
5724 KB |
Output is correct |
51 |
Correct |
1 ms |
5724 KB |
Output is correct |
52 |
Correct |
1 ms |
5724 KB |
Output is correct |
53 |
Correct |
1 ms |
5724 KB |
Output is correct |
54 |
Correct |
2 ms |
5724 KB |
Output is correct |
55 |
Correct |
2 ms |
5720 KB |
Output is correct |
56 |
Correct |
1 ms |
5724 KB |
Output is correct |
57 |
Correct |
1 ms |
5772 KB |
Output is correct |
58 |
Correct |
2 ms |
5724 KB |
Output is correct |
59 |
Correct |
1 ms |
5724 KB |
Output is correct |
60 |
Correct |
1 ms |
5724 KB |
Output is correct |
61 |
Correct |
1 ms |
5724 KB |
Output is correct |
62 |
Correct |
1 ms |
5724 KB |
Output is correct |
63 |
Correct |
1 ms |
5724 KB |
Output is correct |
64 |
Correct |
1 ms |
5724 KB |
Output is correct |
65 |
Correct |
1 ms |
5724 KB |
Output is correct |
66 |
Correct |
1 ms |
5724 KB |
Output is correct |
67 |
Correct |
1 ms |
5724 KB |
Output is correct |
68 |
Correct |
1 ms |
5724 KB |
Output is correct |
69 |
Correct |
1 ms |
5788 KB |
Output is correct |
70 |
Correct |
5 ms |
5724 KB |
Output is correct |
71 |
Correct |
6 ms |
5920 KB |
Output is correct |
72 |
Correct |
5 ms |
5724 KB |
Output is correct |
73 |
Correct |
3 ms |
5724 KB |
Output is correct |
74 |
Correct |
5 ms |
5908 KB |
Output is correct |
75 |
Correct |
4 ms |
5724 KB |
Output is correct |
76 |
Correct |
33 ms |
7004 KB |
Output is correct |
77 |
Correct |
42 ms |
7004 KB |
Output is correct |
78 |
Correct |
55 ms |
7456 KB |
Output is correct |
79 |
Correct |
1 ms |
5724 KB |
Output is correct |
80 |
Correct |
1 ms |
5724 KB |
Output is correct |
81 |
Correct |
1 ms |
5724 KB |
Output is correct |
82 |
Correct |
2 ms |
5724 KB |
Output is correct |
83 |
Correct |
1 ms |
5724 KB |
Output is correct |
84 |
Correct |
8 ms |
5956 KB |
Output is correct |
85 |
Correct |
8 ms |
5724 KB |
Output is correct |
86 |
Correct |
8 ms |
5724 KB |
Output is correct |
87 |
Correct |
8 ms |
5724 KB |
Output is correct |
88 |
Correct |
8 ms |
5956 KB |
Output is correct |
89 |
Correct |
8 ms |
5724 KB |
Output is correct |
90 |
Correct |
73 ms |
7512 KB |
Output is correct |
91 |
Correct |
76 ms |
7512 KB |
Output is correct |
92 |
Correct |
74 ms |
7512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5976 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5720 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5796 KB |
Output is correct |
17 |
Correct |
1 ms |
5724 KB |
Output is correct |
18 |
Correct |
1 ms |
5724 KB |
Output is correct |
19 |
Correct |
1 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5724 KB |
Output is correct |
23 |
Correct |
1 ms |
5724 KB |
Output is correct |
24 |
Correct |
49 ms |
6944 KB |
Output is correct |
25 |
Correct |
51 ms |
6748 KB |
Output is correct |
26 |
Correct |
48 ms |
6744 KB |
Output is correct |
27 |
Correct |
5 ms |
42844 KB |
Output is correct |
28 |
Correct |
5 ms |
42844 KB |
Output is correct |
29 |
Correct |
5 ms |
42844 KB |
Output is correct |
30 |
Correct |
5 ms |
42844 KB |
Output is correct |
31 |
Correct |
5 ms |
42844 KB |
Output is correct |
32 |
Correct |
5 ms |
42844 KB |
Output is correct |
33 |
Correct |
368 ms |
43348 KB |
Output is correct |
34 |
Correct |
361 ms |
43344 KB |
Output is correct |
35 |
Correct |
348 ms |
43248 KB |
Output is correct |
36 |
Correct |
353 ms |
43252 KB |
Output is correct |
37 |
Correct |
374 ms |
43240 KB |
Output is correct |
38 |
Correct |
348 ms |
43256 KB |
Output is correct |
39 |
Execution timed out |
1555 ms |
37972 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
5976 KB |
Output is correct |
2 |
Correct |
1 ms |
5724 KB |
Output is correct |
3 |
Correct |
1 ms |
5724 KB |
Output is correct |
4 |
Correct |
1 ms |
5724 KB |
Output is correct |
5 |
Correct |
1 ms |
5724 KB |
Output is correct |
6 |
Correct |
1 ms |
5724 KB |
Output is correct |
7 |
Correct |
1 ms |
5724 KB |
Output is correct |
8 |
Correct |
1 ms |
5724 KB |
Output is correct |
9 |
Correct |
1 ms |
5724 KB |
Output is correct |
10 |
Correct |
1 ms |
5720 KB |
Output is correct |
11 |
Correct |
1 ms |
5724 KB |
Output is correct |
12 |
Correct |
1 ms |
5724 KB |
Output is correct |
13 |
Correct |
1 ms |
5724 KB |
Output is correct |
14 |
Correct |
1 ms |
5724 KB |
Output is correct |
15 |
Correct |
1 ms |
5724 KB |
Output is correct |
16 |
Correct |
1 ms |
5796 KB |
Output is correct |
17 |
Correct |
1 ms |
5724 KB |
Output is correct |
18 |
Correct |
1 ms |
5724 KB |
Output is correct |
19 |
Correct |
1 ms |
5724 KB |
Output is correct |
20 |
Correct |
1 ms |
5724 KB |
Output is correct |
21 |
Correct |
2 ms |
5724 KB |
Output is correct |
22 |
Correct |
1 ms |
5724 KB |
Output is correct |
23 |
Correct |
1 ms |
5724 KB |
Output is correct |
24 |
Correct |
49 ms |
6944 KB |
Output is correct |
25 |
Correct |
51 ms |
6748 KB |
Output is correct |
26 |
Correct |
48 ms |
6744 KB |
Output is correct |
27 |
Correct |
5 ms |
42844 KB |
Output is correct |
28 |
Correct |
5 ms |
42844 KB |
Output is correct |
29 |
Correct |
5 ms |
42844 KB |
Output is correct |
30 |
Correct |
5 ms |
42844 KB |
Output is correct |
31 |
Correct |
5 ms |
42844 KB |
Output is correct |
32 |
Correct |
5 ms |
42844 KB |
Output is correct |
33 |
Correct |
368 ms |
43348 KB |
Output is correct |
34 |
Correct |
361 ms |
43344 KB |
Output is correct |
35 |
Correct |
348 ms |
43248 KB |
Output is correct |
36 |
Correct |
353 ms |
43252 KB |
Output is correct |
37 |
Correct |
374 ms |
43240 KB |
Output is correct |
38 |
Correct |
348 ms |
43256 KB |
Output is correct |
39 |
Execution timed out |
1555 ms |
37972 KB |
Time limit exceeded |
40 |
Halted |
0 ms |
0 KB |
- |