#include<bits/stdc++.h>
#include "paint.h"
#define MAXN 100007
using namespace std;
int n,m,k,ans;
int c[MAXN];
unordered_set<int> cols[MAXN];
vector<int> where[MAXN];
bool can[MAXN];
int to[2][MAXN];
int best[MAXN],pref[MAXN];
int li[MAXN],tim;
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++){
for(int s:B[i-1]){
cols[i].insert(s);
where[s].push_back(i);
}
}
for(int i=n;i>=1;i--){
for(int f:where[c[i]]){
if(li[f+1]!=tim)to[1-i%2][f+1]=0;
if(li[1]!=tim)to[1-i%2][1]=0;
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);
li[f]=tim+1;
}
tim++;
}
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;
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10072 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
2 ms |
10076 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10072 KB |
Output is correct |
6 |
Correct |
2 ms |
10124 KB |
Output is correct |
7 |
Correct |
2 ms |
10152 KB |
Output is correct |
8 |
Correct |
2 ms |
10076 KB |
Output is correct |
9 |
Correct |
2 ms |
10076 KB |
Output is correct |
10 |
Correct |
2 ms |
10076 KB |
Output is correct |
11 |
Correct |
2 ms |
10076 KB |
Output is correct |
12 |
Correct |
2 ms |
10072 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
2 ms |
10076 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
2 ms |
10076 KB |
Output is correct |
18 |
Correct |
2 ms |
10076 KB |
Output is correct |
19 |
Correct |
2 ms |
10076 KB |
Output is correct |
20 |
Correct |
3 ms |
10076 KB |
Output is correct |
21 |
Correct |
2 ms |
10076 KB |
Output is correct |
22 |
Correct |
16 ms |
18012 KB |
Output is correct |
23 |
Correct |
18 ms |
18084 KB |
Output is correct |
24 |
Correct |
18 ms |
18112 KB |
Output is correct |
25 |
Correct |
3 ms |
10332 KB |
Output is correct |
26 |
Correct |
3 ms |
10384 KB |
Output is correct |
27 |
Correct |
3 ms |
10332 KB |
Output is correct |
28 |
Correct |
3 ms |
10332 KB |
Output is correct |
29 |
Correct |
3 ms |
10332 KB |
Output is correct |
30 |
Correct |
3 ms |
10332 KB |
Output is correct |
31 |
Correct |
6 ms |
12156 KB |
Output is correct |
32 |
Correct |
7 ms |
12124 KB |
Output is correct |
33 |
Correct |
6 ms |
12124 KB |
Output is correct |
34 |
Correct |
10 ms |
12124 KB |
Output is correct |
35 |
Correct |
7 ms |
12120 KB |
Output is correct |
36 |
Correct |
6 ms |
12124 KB |
Output is correct |
37 |
Correct |
21 ms |
18524 KB |
Output is correct |
38 |
Correct |
22 ms |
18612 KB |
Output is correct |
39 |
Correct |
25 ms |
18520 KB |
Output is correct |
40 |
Correct |
7 ms |
11100 KB |
Output is correct |
41 |
Correct |
4 ms |
10588 KB |
Output is correct |
42 |
Correct |
7 ms |
11100 KB |
Output is correct |
43 |
Correct |
5 ms |
10920 KB |
Output is correct |
44 |
Correct |
5 ms |
10840 KB |
Output is correct |
45 |
Correct |
9 ms |
11096 KB |
Output is correct |
46 |
Correct |
32 ms |
27660 KB |
Output is correct |
47 |
Correct |
20 ms |
20572 KB |
Output is correct |
48 |
Correct |
30 ms |
25428 KB |
Output is correct |
49 |
Correct |
29 ms |
25900 KB |
Output is correct |
50 |
Correct |
30 ms |
25172 KB |
Output is correct |
51 |
Correct |
21 ms |
20572 KB |
Output is correct |
52 |
Correct |
6 ms |
11432 KB |
Output is correct |
53 |
Correct |
7 ms |
11448 KB |
Output is correct |
54 |
Correct |
7 ms |
11356 KB |
Output is correct |
55 |
Correct |
8 ms |
11352 KB |
Output is correct |
56 |
Correct |
8 ms |
11356 KB |
Output is correct |
57 |
Correct |
8 ms |
11356 KB |
Output is correct |
58 |
Correct |
46 ms |
30116 KB |
Output is correct |
59 |
Correct |
32 ms |
30296 KB |
Output is correct |
60 |
Correct |
33 ms |
30268 KB |
Output is correct |
61 |
Correct |
42 ms |
30292 KB |
Output is correct |
62 |
Correct |
32 ms |
30176 KB |
Output is correct |
63 |
Correct |
32 ms |
30248 KB |
Output is correct |
64 |
Correct |
36 ms |
28744 KB |
Output is correct |
65 |
Correct |
44 ms |
28720 KB |
Output is correct |
66 |
Correct |
34 ms |
28764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
10072 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
2 ms |
10076 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10072 KB |
Output is correct |
6 |
Correct |
2 ms |
10124 KB |
Output is correct |
7 |
Correct |
2 ms |
10152 KB |
Output is correct |
8 |
Correct |
2 ms |
10076 KB |
Output is correct |
9 |
Correct |
2 ms |
10076 KB |
Output is correct |
10 |
Correct |
2 ms |
10076 KB |
Output is correct |
11 |
Correct |
2 ms |
10076 KB |
Output is correct |
12 |
Correct |
2 ms |
10072 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
2 ms |
10076 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
2 ms |
10076 KB |
Output is correct |
18 |
Correct |
2 ms |
10076 KB |
Output is correct |
19 |
Correct |
2 ms |
10076 KB |
Output is correct |
20 |
Correct |
3 ms |
10076 KB |
Output is correct |
21 |
Correct |
2 ms |
10076 KB |
Output is correct |
22 |
Correct |
2 ms |
10072 KB |
Output is correct |
23 |
Correct |
2 ms |
10076 KB |
Output is correct |
24 |
Correct |
2 ms |
10076 KB |
Output is correct |
25 |
Correct |
2 ms |
10076 KB |
Output is correct |
26 |
Correct |
2 ms |
10076 KB |
Output is correct |
27 |
Correct |
2 ms |
10076 KB |
Output is correct |
28 |
Correct |
2 ms |
10072 KB |
Output is correct |
29 |
Correct |
2 ms |
10076 KB |
Output is correct |
30 |
Correct |
2 ms |
10076 KB |
Output is correct |
31 |
Correct |
2 ms |
10076 KB |
Output is correct |
32 |
Correct |
2 ms |
10120 KB |
Output is correct |
33 |
Correct |
2 ms |
10076 KB |
Output is correct |
34 |
Correct |
2 ms |
10076 KB |
Output is correct |
35 |
Correct |
2 ms |
10076 KB |
Output is correct |
36 |
Correct |
2 ms |
10076 KB |
Output is correct |
37 |
Correct |
2 ms |
10076 KB |
Output is correct |
38 |
Correct |
3 ms |
10076 KB |
Output is correct |
39 |
Incorrect |
2 ms |
10076 KB |
Output isn't correct |
40 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10072 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
3 ms |
10072 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10076 KB |
Output is correct |
6 |
Correct |
2 ms |
10076 KB |
Output is correct |
7 |
Correct |
2 ms |
10072 KB |
Output is correct |
8 |
Correct |
2 ms |
10124 KB |
Output is correct |
9 |
Correct |
2 ms |
10152 KB |
Output is correct |
10 |
Correct |
2 ms |
10076 KB |
Output is correct |
11 |
Correct |
2 ms |
10076 KB |
Output is correct |
12 |
Correct |
2 ms |
10076 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
2 ms |
10072 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
2 ms |
10076 KB |
Output is correct |
18 |
Correct |
2 ms |
10076 KB |
Output is correct |
19 |
Correct |
2 ms |
10076 KB |
Output is correct |
20 |
Correct |
2 ms |
10076 KB |
Output is correct |
21 |
Correct |
2 ms |
10076 KB |
Output is correct |
22 |
Correct |
3 ms |
10076 KB |
Output is correct |
23 |
Correct |
2 ms |
10076 KB |
Output is correct |
24 |
Correct |
16 ms |
18012 KB |
Output is correct |
25 |
Correct |
18 ms |
18084 KB |
Output is correct |
26 |
Correct |
18 ms |
18112 KB |
Output is correct |
27 |
Correct |
2 ms |
10076 KB |
Output is correct |
28 |
Correct |
2 ms |
10076 KB |
Output is correct |
29 |
Correct |
2 ms |
10076 KB |
Output is correct |
30 |
Correct |
2 ms |
10076 KB |
Output is correct |
31 |
Correct |
2 ms |
10072 KB |
Output is correct |
32 |
Correct |
2 ms |
10076 KB |
Output is correct |
33 |
Correct |
2 ms |
10076 KB |
Output is correct |
34 |
Correct |
2 ms |
10076 KB |
Output is correct |
35 |
Correct |
2 ms |
10120 KB |
Output is correct |
36 |
Correct |
2 ms |
10076 KB |
Output is correct |
37 |
Correct |
2 ms |
10076 KB |
Output is correct |
38 |
Correct |
2 ms |
10076 KB |
Output is correct |
39 |
Correct |
2 ms |
10076 KB |
Output is correct |
40 |
Correct |
2 ms |
10076 KB |
Output is correct |
41 |
Correct |
3 ms |
10076 KB |
Output is correct |
42 |
Incorrect |
2 ms |
10076 KB |
Output isn't correct |
43 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10072 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
3 ms |
10072 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10076 KB |
Output is correct |
6 |
Correct |
2 ms |
10076 KB |
Output is correct |
7 |
Correct |
2 ms |
10072 KB |
Output is correct |
8 |
Correct |
2 ms |
10124 KB |
Output is correct |
9 |
Correct |
2 ms |
10152 KB |
Output is correct |
10 |
Correct |
2 ms |
10076 KB |
Output is correct |
11 |
Correct |
2 ms |
10076 KB |
Output is correct |
12 |
Correct |
2 ms |
10076 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
2 ms |
10072 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
2 ms |
10076 KB |
Output is correct |
18 |
Correct |
2 ms |
10076 KB |
Output is correct |
19 |
Correct |
2 ms |
10076 KB |
Output is correct |
20 |
Correct |
2 ms |
10076 KB |
Output is correct |
21 |
Correct |
2 ms |
10076 KB |
Output is correct |
22 |
Correct |
3 ms |
10076 KB |
Output is correct |
23 |
Correct |
2 ms |
10076 KB |
Output is correct |
24 |
Correct |
16 ms |
18012 KB |
Output is correct |
25 |
Correct |
18 ms |
18084 KB |
Output is correct |
26 |
Correct |
18 ms |
18112 KB |
Output is correct |
27 |
Correct |
3 ms |
10332 KB |
Output is correct |
28 |
Correct |
3 ms |
10384 KB |
Output is correct |
29 |
Correct |
3 ms |
10332 KB |
Output is correct |
30 |
Correct |
3 ms |
10332 KB |
Output is correct |
31 |
Correct |
3 ms |
10332 KB |
Output is correct |
32 |
Correct |
3 ms |
10332 KB |
Output is correct |
33 |
Correct |
6 ms |
12156 KB |
Output is correct |
34 |
Correct |
7 ms |
12124 KB |
Output is correct |
35 |
Correct |
6 ms |
12124 KB |
Output is correct |
36 |
Correct |
10 ms |
12124 KB |
Output is correct |
37 |
Correct |
7 ms |
12120 KB |
Output is correct |
38 |
Correct |
6 ms |
12124 KB |
Output is correct |
39 |
Correct |
21 ms |
18524 KB |
Output is correct |
40 |
Correct |
22 ms |
18612 KB |
Output is correct |
41 |
Correct |
25 ms |
18520 KB |
Output is correct |
42 |
Correct |
2 ms |
10076 KB |
Output is correct |
43 |
Correct |
2 ms |
10076 KB |
Output is correct |
44 |
Correct |
2 ms |
10076 KB |
Output is correct |
45 |
Correct |
2 ms |
10076 KB |
Output is correct |
46 |
Correct |
2 ms |
10072 KB |
Output is correct |
47 |
Correct |
2 ms |
10076 KB |
Output is correct |
48 |
Correct |
2 ms |
10076 KB |
Output is correct |
49 |
Correct |
2 ms |
10076 KB |
Output is correct |
50 |
Correct |
2 ms |
10120 KB |
Output is correct |
51 |
Correct |
2 ms |
10076 KB |
Output is correct |
52 |
Correct |
2 ms |
10076 KB |
Output is correct |
53 |
Correct |
2 ms |
10076 KB |
Output is correct |
54 |
Correct |
2 ms |
10076 KB |
Output is correct |
55 |
Correct |
2 ms |
10076 KB |
Output is correct |
56 |
Correct |
3 ms |
10076 KB |
Output is correct |
57 |
Incorrect |
2 ms |
10076 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
10072 KB |
Output is correct |
2 |
Correct |
2 ms |
10076 KB |
Output is correct |
3 |
Correct |
3 ms |
10072 KB |
Output is correct |
4 |
Correct |
2 ms |
10076 KB |
Output is correct |
5 |
Correct |
2 ms |
10076 KB |
Output is correct |
6 |
Correct |
2 ms |
10076 KB |
Output is correct |
7 |
Correct |
2 ms |
10072 KB |
Output is correct |
8 |
Correct |
2 ms |
10124 KB |
Output is correct |
9 |
Correct |
2 ms |
10152 KB |
Output is correct |
10 |
Correct |
2 ms |
10076 KB |
Output is correct |
11 |
Correct |
2 ms |
10076 KB |
Output is correct |
12 |
Correct |
2 ms |
10076 KB |
Output is correct |
13 |
Correct |
2 ms |
10076 KB |
Output is correct |
14 |
Correct |
2 ms |
10072 KB |
Output is correct |
15 |
Correct |
2 ms |
10076 KB |
Output is correct |
16 |
Correct |
2 ms |
10076 KB |
Output is correct |
17 |
Correct |
2 ms |
10076 KB |
Output is correct |
18 |
Correct |
2 ms |
10076 KB |
Output is correct |
19 |
Correct |
2 ms |
10076 KB |
Output is correct |
20 |
Correct |
2 ms |
10076 KB |
Output is correct |
21 |
Correct |
2 ms |
10076 KB |
Output is correct |
22 |
Correct |
3 ms |
10076 KB |
Output is correct |
23 |
Correct |
2 ms |
10076 KB |
Output is correct |
24 |
Correct |
16 ms |
18012 KB |
Output is correct |
25 |
Correct |
18 ms |
18084 KB |
Output is correct |
26 |
Correct |
18 ms |
18112 KB |
Output is correct |
27 |
Correct |
3 ms |
10332 KB |
Output is correct |
28 |
Correct |
3 ms |
10384 KB |
Output is correct |
29 |
Correct |
3 ms |
10332 KB |
Output is correct |
30 |
Correct |
3 ms |
10332 KB |
Output is correct |
31 |
Correct |
3 ms |
10332 KB |
Output is correct |
32 |
Correct |
3 ms |
10332 KB |
Output is correct |
33 |
Correct |
6 ms |
12156 KB |
Output is correct |
34 |
Correct |
7 ms |
12124 KB |
Output is correct |
35 |
Correct |
6 ms |
12124 KB |
Output is correct |
36 |
Correct |
10 ms |
12124 KB |
Output is correct |
37 |
Correct |
7 ms |
12120 KB |
Output is correct |
38 |
Correct |
6 ms |
12124 KB |
Output is correct |
39 |
Correct |
21 ms |
18524 KB |
Output is correct |
40 |
Correct |
22 ms |
18612 KB |
Output is correct |
41 |
Correct |
25 ms |
18520 KB |
Output is correct |
42 |
Correct |
7 ms |
11100 KB |
Output is correct |
43 |
Correct |
4 ms |
10588 KB |
Output is correct |
44 |
Correct |
7 ms |
11100 KB |
Output is correct |
45 |
Correct |
5 ms |
10920 KB |
Output is correct |
46 |
Correct |
5 ms |
10840 KB |
Output is correct |
47 |
Correct |
9 ms |
11096 KB |
Output is correct |
48 |
Correct |
32 ms |
27660 KB |
Output is correct |
49 |
Correct |
20 ms |
20572 KB |
Output is correct |
50 |
Correct |
30 ms |
25428 KB |
Output is correct |
51 |
Correct |
29 ms |
25900 KB |
Output is correct |
52 |
Correct |
30 ms |
25172 KB |
Output is correct |
53 |
Correct |
21 ms |
20572 KB |
Output is correct |
54 |
Correct |
6 ms |
11432 KB |
Output is correct |
55 |
Correct |
7 ms |
11448 KB |
Output is correct |
56 |
Correct |
7 ms |
11356 KB |
Output is correct |
57 |
Correct |
8 ms |
11352 KB |
Output is correct |
58 |
Correct |
8 ms |
11356 KB |
Output is correct |
59 |
Correct |
8 ms |
11356 KB |
Output is correct |
60 |
Correct |
46 ms |
30116 KB |
Output is correct |
61 |
Correct |
32 ms |
30296 KB |
Output is correct |
62 |
Correct |
33 ms |
30268 KB |
Output is correct |
63 |
Correct |
42 ms |
30292 KB |
Output is correct |
64 |
Correct |
32 ms |
30176 KB |
Output is correct |
65 |
Correct |
32 ms |
30248 KB |
Output is correct |
66 |
Correct |
36 ms |
28744 KB |
Output is correct |
67 |
Correct |
44 ms |
28720 KB |
Output is correct |
68 |
Correct |
34 ms |
28764 KB |
Output is correct |
69 |
Correct |
2 ms |
10076 KB |
Output is correct |
70 |
Correct |
2 ms |
10076 KB |
Output is correct |
71 |
Correct |
2 ms |
10076 KB |
Output is correct |
72 |
Correct |
2 ms |
10076 KB |
Output is correct |
73 |
Correct |
2 ms |
10072 KB |
Output is correct |
74 |
Correct |
2 ms |
10076 KB |
Output is correct |
75 |
Correct |
2 ms |
10076 KB |
Output is correct |
76 |
Correct |
2 ms |
10076 KB |
Output is correct |
77 |
Correct |
2 ms |
10120 KB |
Output is correct |
78 |
Correct |
2 ms |
10076 KB |
Output is correct |
79 |
Correct |
2 ms |
10076 KB |
Output is correct |
80 |
Correct |
2 ms |
10076 KB |
Output is correct |
81 |
Correct |
2 ms |
10076 KB |
Output is correct |
82 |
Correct |
2 ms |
10076 KB |
Output is correct |
83 |
Correct |
3 ms |
10076 KB |
Output is correct |
84 |
Incorrect |
2 ms |
10076 KB |
Output isn't correct |
85 |
Halted |
0 ms |
0 KB |
- |