#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;
unordered_set<int> poss;
FOR(j,N-M+1){
vi curr;
FOA(v, f[C[j]]){
if(poss.count(v)){
ok.insert(j);
continue;
}
}
poss.clear();
FOA(v, f[C[j]]) poss.insert(v);
FORi(i,1,M){
unordered_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;
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
16 ms |
468 KB |
Output is correct |
14 |
Correct |
10 ms |
384 KB |
Output is correct |
15 |
Correct |
9 ms |
340 KB |
Output is correct |
16 |
Correct |
10 ms |
388 KB |
Output is correct |
17 |
Correct |
9 ms |
388 KB |
Output is correct |
18 |
Correct |
9 ms |
340 KB |
Output is correct |
19 |
Correct |
6 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
72 ms |
11948 KB |
Output is correct |
23 |
Correct |
85 ms |
11948 KB |
Output is correct |
24 |
Correct |
96 ms |
12160 KB |
Output is correct |
25 |
Correct |
9 ms |
1364 KB |
Output is correct |
26 |
Correct |
9 ms |
1364 KB |
Output is correct |
27 |
Correct |
6 ms |
844 KB |
Output is correct |
28 |
Correct |
6 ms |
492 KB |
Output is correct |
29 |
Correct |
6 ms |
340 KB |
Output is correct |
30 |
Correct |
9 ms |
340 KB |
Output is correct |
31 |
Execution timed out |
1579 ms |
3260 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
16 ms |
468 KB |
Output is correct |
14 |
Correct |
10 ms |
384 KB |
Output is correct |
15 |
Correct |
9 ms |
340 KB |
Output is correct |
16 |
Correct |
10 ms |
388 KB |
Output is correct |
17 |
Correct |
9 ms |
388 KB |
Output is correct |
18 |
Correct |
9 ms |
340 KB |
Output is correct |
19 |
Correct |
6 ms |
468 KB |
Output is correct |
20 |
Correct |
5 ms |
468 KB |
Output is correct |
21 |
Correct |
4 ms |
468 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
15 ms |
312 KB |
Output is correct |
29 |
Correct |
3 ms |
212 KB |
Output is correct |
30 |
Correct |
2 ms |
212 KB |
Output is correct |
31 |
Correct |
3 ms |
212 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
6 ms |
340 KB |
Output is correct |
34 |
Correct |
7 ms |
340 KB |
Output is correct |
35 |
Correct |
3 ms |
340 KB |
Output is correct |
36 |
Correct |
8 ms |
368 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 |
212 KB |
Output is correct |
40 |
Correct |
3 ms |
340 KB |
Output is correct |
41 |
Correct |
5 ms |
348 KB |
Output is correct |
42 |
Correct |
2 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
33 ms |
304 KB |
Output is correct |
46 |
Correct |
8 ms |
212 KB |
Output is correct |
47 |
Correct |
6 ms |
212 KB |
Output is correct |
48 |
Correct |
6 ms |
308 KB |
Output is correct |
49 |
Correct |
5 ms |
212 KB |
Output is correct |
50 |
Correct |
9 ms |
340 KB |
Output is correct |
51 |
Correct |
10 ms |
340 KB |
Output is correct |
52 |
Correct |
9 ms |
340 KB |
Output is correct |
53 |
Correct |
9 ms |
340 KB |
Output is correct |
54 |
Correct |
10 ms |
388 KB |
Output is correct |
55 |
Correct |
16 ms |
388 KB |
Output is correct |
56 |
Correct |
5 ms |
468 KB |
Output is correct |
57 |
Correct |
14 ms |
368 KB |
Output is correct |
58 |
Correct |
5 ms |
468 KB |
Output is correct |
59 |
Correct |
14 ms |
376 KB |
Output is correct |
60 |
Correct |
5 ms |
468 KB |
Output is correct |
61 |
Correct |
10 ms |
372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
16 ms |
468 KB |
Output is correct |
16 |
Correct |
10 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
388 KB |
Output is correct |
19 |
Correct |
9 ms |
388 KB |
Output is correct |
20 |
Correct |
9 ms |
340 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
5 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
468 KB |
Output is correct |
24 |
Correct |
72 ms |
11948 KB |
Output is correct |
25 |
Correct |
85 ms |
11948 KB |
Output is correct |
26 |
Correct |
96 ms |
12160 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
15 ms |
312 KB |
Output is correct |
32 |
Correct |
3 ms |
212 KB |
Output is correct |
33 |
Correct |
2 ms |
212 KB |
Output is correct |
34 |
Correct |
3 ms |
212 KB |
Output is correct |
35 |
Correct |
3 ms |
212 KB |
Output is correct |
36 |
Correct |
6 ms |
340 KB |
Output is correct |
37 |
Correct |
7 ms |
340 KB |
Output is correct |
38 |
Correct |
3 ms |
340 KB |
Output is correct |
39 |
Correct |
8 ms |
368 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 |
212 KB |
Output is correct |
43 |
Correct |
3 ms |
340 KB |
Output is correct |
44 |
Correct |
5 ms |
348 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
2 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
33 ms |
304 KB |
Output is correct |
49 |
Correct |
8 ms |
212 KB |
Output is correct |
50 |
Correct |
6 ms |
212 KB |
Output is correct |
51 |
Correct |
6 ms |
308 KB |
Output is correct |
52 |
Correct |
5 ms |
212 KB |
Output is correct |
53 |
Correct |
9 ms |
340 KB |
Output is correct |
54 |
Correct |
10 ms |
340 KB |
Output is correct |
55 |
Correct |
9 ms |
340 KB |
Output is correct |
56 |
Correct |
9 ms |
340 KB |
Output is correct |
57 |
Correct |
10 ms |
388 KB |
Output is correct |
58 |
Correct |
16 ms |
388 KB |
Output is correct |
59 |
Correct |
5 ms |
468 KB |
Output is correct |
60 |
Correct |
14 ms |
368 KB |
Output is correct |
61 |
Correct |
5 ms |
468 KB |
Output is correct |
62 |
Correct |
14 ms |
376 KB |
Output is correct |
63 |
Correct |
5 ms |
468 KB |
Output is correct |
64 |
Correct |
10 ms |
372 KB |
Output is correct |
65 |
Correct |
161 ms |
320 KB |
Output is correct |
66 |
Correct |
49 ms |
316 KB |
Output is correct |
67 |
Correct |
347 ms |
444 KB |
Output is correct |
68 |
Correct |
138 ms |
320 KB |
Output is correct |
69 |
Correct |
273 ms |
324 KB |
Output is correct |
70 |
Correct |
64 ms |
516 KB |
Output is correct |
71 |
Correct |
65 ms |
516 KB |
Output is correct |
72 |
Correct |
42 ms |
496 KB |
Output is correct |
73 |
Correct |
8 ms |
440 KB |
Output is correct |
74 |
Correct |
55 ms |
468 KB |
Output is correct |
75 |
Correct |
45 ms |
468 KB |
Output is correct |
76 |
Correct |
44 ms |
7312 KB |
Output is correct |
77 |
Correct |
32 ms |
8628 KB |
Output is correct |
78 |
Correct |
47 ms |
9672 KB |
Output is correct |
79 |
Correct |
933 ms |
344 KB |
Output is correct |
80 |
Correct |
813 ms |
456 KB |
Output is correct |
81 |
Correct |
863 ms |
340 KB |
Output is correct |
82 |
Correct |
831 ms |
340 KB |
Output is correct |
83 |
Correct |
889 ms |
464 KB |
Output is correct |
84 |
Correct |
100 ms |
596 KB |
Output is correct |
85 |
Correct |
93 ms |
604 KB |
Output is correct |
86 |
Correct |
97 ms |
596 KB |
Output is correct |
87 |
Correct |
94 ms |
596 KB |
Output is correct |
88 |
Correct |
101 ms |
596 KB |
Output is correct |
89 |
Correct |
104 ms |
596 KB |
Output is correct |
90 |
Correct |
75 ms |
10228 KB |
Output is correct |
91 |
Correct |
73 ms |
10140 KB |
Output is correct |
92 |
Correct |
70 ms |
10172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
16 ms |
468 KB |
Output is correct |
16 |
Correct |
10 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
388 KB |
Output is correct |
19 |
Correct |
9 ms |
388 KB |
Output is correct |
20 |
Correct |
9 ms |
340 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
5 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
468 KB |
Output is correct |
24 |
Correct |
72 ms |
11948 KB |
Output is correct |
25 |
Correct |
85 ms |
11948 KB |
Output is correct |
26 |
Correct |
96 ms |
12160 KB |
Output is correct |
27 |
Correct |
9 ms |
1364 KB |
Output is correct |
28 |
Correct |
9 ms |
1364 KB |
Output is correct |
29 |
Correct |
6 ms |
844 KB |
Output is correct |
30 |
Correct |
6 ms |
492 KB |
Output is correct |
31 |
Correct |
6 ms |
340 KB |
Output is correct |
32 |
Correct |
9 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1579 ms |
3260 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
296 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
16 ms |
468 KB |
Output is correct |
16 |
Correct |
10 ms |
384 KB |
Output is correct |
17 |
Correct |
9 ms |
340 KB |
Output is correct |
18 |
Correct |
10 ms |
388 KB |
Output is correct |
19 |
Correct |
9 ms |
388 KB |
Output is correct |
20 |
Correct |
9 ms |
340 KB |
Output is correct |
21 |
Correct |
6 ms |
468 KB |
Output is correct |
22 |
Correct |
5 ms |
468 KB |
Output is correct |
23 |
Correct |
4 ms |
468 KB |
Output is correct |
24 |
Correct |
72 ms |
11948 KB |
Output is correct |
25 |
Correct |
85 ms |
11948 KB |
Output is correct |
26 |
Correct |
96 ms |
12160 KB |
Output is correct |
27 |
Correct |
9 ms |
1364 KB |
Output is correct |
28 |
Correct |
9 ms |
1364 KB |
Output is correct |
29 |
Correct |
6 ms |
844 KB |
Output is correct |
30 |
Correct |
6 ms |
492 KB |
Output is correct |
31 |
Correct |
6 ms |
340 KB |
Output is correct |
32 |
Correct |
9 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1579 ms |
3260 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |