#include "paint.h"
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B){
vector<vector<int>> G(N+1);
vector<set<int>> S(M);
for(int i=0;i<M;i++)for(int x:B[i]) S[i].insert(x);
for(int i=0;i<=N-M;i++){
bool ok = false;
for(int j=0;j<M;j++){
if(ok) break;
bool now = true;
for(int k=i;k<i+M;k++){
if(!S[(j+k-i)%M].count(C[k])) now = false;
}
if(now) ok = true;
}
if(ok){
for(int j=i+1;j<=i+M;j++) G[i].push_back(j);
}
}
queue<int> q;
q.push(0);
vector<int> dist(N+1,1e9);
dist[0] = 0;
while(!q.empty()){
int pos = q.front();
q.pop();
for(int x:G[pos]){
if(dist[x] != 1e9) continue;
dist[x] = dist[pos] + 1;
q.push(x);
}
}
if(dist[N] == 1e9) return -1;
else return dist[N];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
93 ms |
616 KB |
Output is correct |
14 |
Correct |
92 ms |
584 KB |
Output is correct |
15 |
Correct |
103 ms |
588 KB |
Output is correct |
16 |
Correct |
96 ms |
536 KB |
Output is correct |
17 |
Correct |
99 ms |
648 KB |
Output is correct |
18 |
Correct |
99 ms |
588 KB |
Output is correct |
19 |
Correct |
295 ms |
368 KB |
Output is correct |
20 |
Correct |
289 ms |
368 KB |
Output is correct |
21 |
Correct |
295 ms |
368 KB |
Output is correct |
22 |
Execution timed out |
1566 ms |
5724 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
93 ms |
616 KB |
Output is correct |
14 |
Correct |
92 ms |
584 KB |
Output is correct |
15 |
Correct |
103 ms |
588 KB |
Output is correct |
16 |
Correct |
96 ms |
536 KB |
Output is correct |
17 |
Correct |
99 ms |
648 KB |
Output is correct |
18 |
Correct |
99 ms |
588 KB |
Output is correct |
19 |
Correct |
295 ms |
368 KB |
Output is correct |
20 |
Correct |
289 ms |
368 KB |
Output is correct |
21 |
Correct |
295 ms |
368 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
3 ms |
212 KB |
Output is correct |
30 |
Correct |
3 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
7 ms |
212 KB |
Output is correct |
33 |
Correct |
46 ms |
584 KB |
Output is correct |
34 |
Correct |
52 ms |
580 KB |
Output is correct |
35 |
Correct |
17 ms |
436 KB |
Output is correct |
36 |
Correct |
37 ms |
504 KB |
Output is correct |
37 |
Correct |
30 ms |
504 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
96 ms |
340 KB |
Output is correct |
41 |
Correct |
30 ms |
400 KB |
Output is correct |
42 |
Correct |
66 ms |
340 KB |
Output is correct |
43 |
Correct |
12 ms |
352 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
7 ms |
312 KB |
Output is correct |
47 |
Correct |
11 ms |
212 KB |
Output is correct |
48 |
Correct |
14 ms |
212 KB |
Output is correct |
49 |
Correct |
18 ms |
324 KB |
Output is correct |
50 |
Correct |
104 ms |
588 KB |
Output is correct |
51 |
Correct |
88 ms |
640 KB |
Output is correct |
52 |
Correct |
83 ms |
648 KB |
Output is correct |
53 |
Correct |
102 ms |
636 KB |
Output is correct |
54 |
Correct |
98 ms |
560 KB |
Output is correct |
55 |
Correct |
82 ms |
716 KB |
Output is correct |
56 |
Correct |
290 ms |
376 KB |
Output is correct |
57 |
Correct |
80 ms |
616 KB |
Output is correct |
58 |
Correct |
302 ms |
368 KB |
Output is correct |
59 |
Correct |
93 ms |
640 KB |
Output is correct |
60 |
Correct |
292 ms |
372 KB |
Output is correct |
61 |
Correct |
103 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
93 ms |
616 KB |
Output is correct |
16 |
Correct |
92 ms |
584 KB |
Output is correct |
17 |
Correct |
103 ms |
588 KB |
Output is correct |
18 |
Correct |
96 ms |
536 KB |
Output is correct |
19 |
Correct |
99 ms |
648 KB |
Output is correct |
20 |
Correct |
99 ms |
588 KB |
Output is correct |
21 |
Correct |
295 ms |
368 KB |
Output is correct |
22 |
Correct |
289 ms |
368 KB |
Output is correct |
23 |
Correct |
295 ms |
368 KB |
Output is correct |
24 |
Execution timed out |
1566 ms |
5724 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
93 ms |
616 KB |
Output is correct |
16 |
Correct |
92 ms |
584 KB |
Output is correct |
17 |
Correct |
103 ms |
588 KB |
Output is correct |
18 |
Correct |
96 ms |
536 KB |
Output is correct |
19 |
Correct |
99 ms |
648 KB |
Output is correct |
20 |
Correct |
99 ms |
588 KB |
Output is correct |
21 |
Correct |
295 ms |
368 KB |
Output is correct |
22 |
Correct |
289 ms |
368 KB |
Output is correct |
23 |
Correct |
295 ms |
368 KB |
Output is correct |
24 |
Execution timed out |
1566 ms |
5724 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
93 ms |
616 KB |
Output is correct |
16 |
Correct |
92 ms |
584 KB |
Output is correct |
17 |
Correct |
103 ms |
588 KB |
Output is correct |
18 |
Correct |
96 ms |
536 KB |
Output is correct |
19 |
Correct |
99 ms |
648 KB |
Output is correct |
20 |
Correct |
99 ms |
588 KB |
Output is correct |
21 |
Correct |
295 ms |
368 KB |
Output is correct |
22 |
Correct |
289 ms |
368 KB |
Output is correct |
23 |
Correct |
295 ms |
368 KB |
Output is correct |
24 |
Execution timed out |
1566 ms |
5724 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |