#include<bits/stdc++.h>
using namespace std;
#include "paint.h"
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
vector<int> A, vector<std::vector<int>> B) {
map<int, vector<int>> f;
FOR(i,M){
FOA(v, B[i]){
f[v].push_back(i);
}
}
set<int> ok;
FOR(j,N-M+1){
vi curr;
set<int> poss;
FOA(v, f[C[j]]) poss.insert(v);
FORi(i,1,M){
set<int> npos;
FOA(v, f[C[j+i]]){
int pp = (v-i + M)%M;
if(poss.count(pp)) npos.insert(pp);
}
poss = npos;
}
if(poss.empty()) continue;
ok.insert(j);
}
if(!ok.count(0)) return -1;
int p=0;
int cp=M;
int ans = 1;
while(cp<N){
//cout<<p<<" "<<cp<<endl;
while(!ok.count(cp)) cp--;
if(cp<=p) return -1;
p = cp;
cp+=M;
ans++;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
300 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 |
232 KB |
Output is correct |
13 |
Correct |
9 ms |
308 KB |
Output is correct |
14 |
Correct |
6 ms |
304 KB |
Output is correct |
15 |
Correct |
7 ms |
396 KB |
Output is correct |
16 |
Correct |
7 ms |
392 KB |
Output is correct |
17 |
Correct |
7 ms |
340 KB |
Output is correct |
18 |
Correct |
7 ms |
396 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
468 KB |
Output is correct |
22 |
Correct |
68 ms |
12560 KB |
Output is correct |
23 |
Correct |
68 ms |
12624 KB |
Output is correct |
24 |
Correct |
70 ms |
12552 KB |
Output is correct |
25 |
Correct |
7 ms |
1364 KB |
Output is correct |
26 |
Correct |
11 ms |
1420 KB |
Output is correct |
27 |
Correct |
5 ms |
952 KB |
Output is correct |
28 |
Correct |
4 ms |
468 KB |
Output is correct |
29 |
Correct |
5 ms |
416 KB |
Output is correct |
30 |
Correct |
5 ms |
412 KB |
Output is correct |
31 |
Execution timed out |
1579 ms |
3412 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
288 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
300 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 |
232 KB |
Output is correct |
13 |
Correct |
9 ms |
308 KB |
Output is correct |
14 |
Correct |
6 ms |
304 KB |
Output is correct |
15 |
Correct |
7 ms |
396 KB |
Output is correct |
16 |
Correct |
7 ms |
392 KB |
Output is correct |
17 |
Correct |
7 ms |
340 KB |
Output is correct |
18 |
Correct |
7 ms |
396 KB |
Output is correct |
19 |
Correct |
3 ms |
468 KB |
Output is correct |
20 |
Correct |
3 ms |
468 KB |
Output is correct |
21 |
Correct |
3 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
304 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 |
23 ms |
308 KB |
Output is correct |
29 |
Correct |
2 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
212 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
5 ms |
340 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
428 KB |
Output is correct |
37 |
Correct |
5 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
300 KB |
Output is correct |
40 |
Correct |
2 ms |
432 KB |
Output is correct |
41 |
Correct |
3 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
304 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
39 ms |
212 KB |
Output is correct |
46 |
Correct |
4 ms |
212 KB |
Output is correct |
47 |
Correct |
3 ms |
212 KB |
Output is correct |
48 |
Correct |
3 ms |
212 KB |
Output is correct |
49 |
Correct |
3 ms |
212 KB |
Output is correct |
50 |
Correct |
6 ms |
396 KB |
Output is correct |
51 |
Correct |
6 ms |
400 KB |
Output is correct |
52 |
Correct |
7 ms |
308 KB |
Output is correct |
53 |
Correct |
7 ms |
396 KB |
Output is correct |
54 |
Correct |
7 ms |
300 KB |
Output is correct |
55 |
Correct |
7 ms |
340 KB |
Output is correct |
56 |
Correct |
3 ms |
468 KB |
Output is correct |
57 |
Correct |
6 ms |
304 KB |
Output is correct |
58 |
Correct |
3 ms |
468 KB |
Output is correct |
59 |
Correct |
10 ms |
368 KB |
Output is correct |
60 |
Correct |
4 ms |
468 KB |
Output is correct |
61 |
Correct |
7 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
300 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 |
232 KB |
Output is correct |
15 |
Correct |
9 ms |
308 KB |
Output is correct |
16 |
Correct |
6 ms |
304 KB |
Output is correct |
17 |
Correct |
7 ms |
396 KB |
Output is correct |
18 |
Correct |
7 ms |
392 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
7 ms |
396 KB |
Output is correct |
21 |
Correct |
3 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
68 ms |
12560 KB |
Output is correct |
25 |
Correct |
68 ms |
12624 KB |
Output is correct |
26 |
Correct |
70 ms |
12552 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
23 ms |
308 KB |
Output is correct |
32 |
Correct |
2 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
212 KB |
Output is correct |
34 |
Correct |
2 ms |
212 KB |
Output is correct |
35 |
Correct |
2 ms |
212 KB |
Output is correct |
36 |
Correct |
6 ms |
340 KB |
Output is correct |
37 |
Correct |
5 ms |
340 KB |
Output is correct |
38 |
Correct |
2 ms |
340 KB |
Output is correct |
39 |
Correct |
4 ms |
428 KB |
Output is correct |
40 |
Correct |
5 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
300 KB |
Output is correct |
43 |
Correct |
2 ms |
432 KB |
Output is correct |
44 |
Correct |
3 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
2 ms |
304 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
39 ms |
212 KB |
Output is correct |
49 |
Correct |
4 ms |
212 KB |
Output is correct |
50 |
Correct |
3 ms |
212 KB |
Output is correct |
51 |
Correct |
3 ms |
212 KB |
Output is correct |
52 |
Correct |
3 ms |
212 KB |
Output is correct |
53 |
Correct |
6 ms |
396 KB |
Output is correct |
54 |
Correct |
6 ms |
400 KB |
Output is correct |
55 |
Correct |
7 ms |
308 KB |
Output is correct |
56 |
Correct |
7 ms |
396 KB |
Output is correct |
57 |
Correct |
7 ms |
300 KB |
Output is correct |
58 |
Correct |
7 ms |
340 KB |
Output is correct |
59 |
Correct |
3 ms |
468 KB |
Output is correct |
60 |
Correct |
6 ms |
304 KB |
Output is correct |
61 |
Correct |
3 ms |
468 KB |
Output is correct |
62 |
Correct |
10 ms |
368 KB |
Output is correct |
63 |
Correct |
4 ms |
468 KB |
Output is correct |
64 |
Correct |
7 ms |
340 KB |
Output is correct |
65 |
Correct |
253 ms |
340 KB |
Output is correct |
66 |
Correct |
64 ms |
308 KB |
Output is correct |
67 |
Correct |
565 ms |
332 KB |
Output is correct |
68 |
Correct |
212 ms |
212 KB |
Output is correct |
69 |
Correct |
467 ms |
440 KB |
Output is correct |
70 |
Correct |
54 ms |
588 KB |
Output is correct |
71 |
Correct |
57 ms |
596 KB |
Output is correct |
72 |
Correct |
41 ms |
508 KB |
Output is correct |
73 |
Correct |
8 ms |
468 KB |
Output is correct |
74 |
Correct |
51 ms |
548 KB |
Output is correct |
75 |
Correct |
36 ms |
560 KB |
Output is correct |
76 |
Correct |
38 ms |
7840 KB |
Output is correct |
77 |
Correct |
31 ms |
9292 KB |
Output is correct |
78 |
Correct |
44 ms |
10412 KB |
Output is correct |
79 |
Correct |
1273 ms |
460 KB |
Output is correct |
80 |
Correct |
1267 ms |
464 KB |
Output is correct |
81 |
Correct |
1269 ms |
596 KB |
Output is correct |
82 |
Correct |
1266 ms |
464 KB |
Output is correct |
83 |
Correct |
1262 ms |
596 KB |
Output is correct |
84 |
Correct |
94 ms |
596 KB |
Output is correct |
85 |
Correct |
93 ms |
596 KB |
Output is correct |
86 |
Correct |
88 ms |
596 KB |
Output is correct |
87 |
Correct |
85 ms |
668 KB |
Output is correct |
88 |
Correct |
89 ms |
676 KB |
Output is correct |
89 |
Correct |
87 ms |
596 KB |
Output is correct |
90 |
Correct |
73 ms |
11208 KB |
Output is correct |
91 |
Correct |
67 ms |
11024 KB |
Output is correct |
92 |
Correct |
72 ms |
11068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
300 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 |
232 KB |
Output is correct |
15 |
Correct |
9 ms |
308 KB |
Output is correct |
16 |
Correct |
6 ms |
304 KB |
Output is correct |
17 |
Correct |
7 ms |
396 KB |
Output is correct |
18 |
Correct |
7 ms |
392 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
7 ms |
396 KB |
Output is correct |
21 |
Correct |
3 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
68 ms |
12560 KB |
Output is correct |
25 |
Correct |
68 ms |
12624 KB |
Output is correct |
26 |
Correct |
70 ms |
12552 KB |
Output is correct |
27 |
Correct |
7 ms |
1364 KB |
Output is correct |
28 |
Correct |
11 ms |
1420 KB |
Output is correct |
29 |
Correct |
5 ms |
952 KB |
Output is correct |
30 |
Correct |
4 ms |
468 KB |
Output is correct |
31 |
Correct |
5 ms |
416 KB |
Output is correct |
32 |
Correct |
5 ms |
412 KB |
Output is correct |
33 |
Execution timed out |
1579 ms |
3412 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
288 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
300 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 |
232 KB |
Output is correct |
15 |
Correct |
9 ms |
308 KB |
Output is correct |
16 |
Correct |
6 ms |
304 KB |
Output is correct |
17 |
Correct |
7 ms |
396 KB |
Output is correct |
18 |
Correct |
7 ms |
392 KB |
Output is correct |
19 |
Correct |
7 ms |
340 KB |
Output is correct |
20 |
Correct |
7 ms |
396 KB |
Output is correct |
21 |
Correct |
3 ms |
468 KB |
Output is correct |
22 |
Correct |
3 ms |
468 KB |
Output is correct |
23 |
Correct |
3 ms |
468 KB |
Output is correct |
24 |
Correct |
68 ms |
12560 KB |
Output is correct |
25 |
Correct |
68 ms |
12624 KB |
Output is correct |
26 |
Correct |
70 ms |
12552 KB |
Output is correct |
27 |
Correct |
7 ms |
1364 KB |
Output is correct |
28 |
Correct |
11 ms |
1420 KB |
Output is correct |
29 |
Correct |
5 ms |
952 KB |
Output is correct |
30 |
Correct |
4 ms |
468 KB |
Output is correct |
31 |
Correct |
5 ms |
416 KB |
Output is correct |
32 |
Correct |
5 ms |
412 KB |
Output is correct |
33 |
Execution timed out |
1579 ms |
3412 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |