#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 M, N;
vi c;
map<int, vector<int>> f;
struct seg{
set<int> val;
seg *L, *R;
set<int> merge(set<int> &a, int as, set<int> &b){
set<int> ans;
FOA(v,a){
if(b.count((v + as)%M)) ans.insert(v);
}
return ans;
}
void build(int l=0, int r=N-1){
if(l==r){
FOA(v, f[c[l]]){
val.insert(v);
}
}
else{
L = new seg;
R = new seg;
L->build(l,MID);
R->build(MID+1,r);
val = merge(L->val, MID-l+1, R->val);
}
}
set<int> query(int rl, int rr, int l=0, int r=N-1){
if(rl<=l && r<=rr) return val;
else if(rr<l || r<rl) return set<int>();
else{
set<int> sl = L->query(rl,rr,l,MID);
set<int> sr = R->query(rl,rr,MID+1,r);
if(rr<=MID){
/*
cout<<"Return left "<<l<<" "<<r<<": ";
FOA(v,sl) cout<<v<<" ";
cout<<endl;*/
return sl;
}
if(rl>MID){
/*
cout<<"Return right "<<l<<" "<<r<<": ";
FOA(v,sr) cout<<v<<" ";
cout<<endl;*/
return sr;
}
//cout<<"merge "<<l<<" "<<r<<": ";
set<int> qq;
if(l<=rl) qq = merge(sl, MID-rl+1, sr);
else qq = merge(sl, MID-l+1, sr);
/*
FOA(v, sl) cout<<v<<" ";
cout<<" | ";
FOA(v, sr) cout<<v<<" ";
cout<<" | ";
FOA(v, qq) cout<<v<<" ";
cout<<endl;*/
return qq;
}
}
void print(int l=0, int r=N-1){
cout<<l<<" "<<r<<": ";
FOA(v, val) cout<<v<<" ";
cout<<endl;
if(l!=r){
L->print(l, MID);
R->print(MID+1,r);
}
}
};
int minimumInstructions(int n, int m, int K, std::vector<int> C,
vector<int> A, vector<std::vector<int>> B) {
M = m;
N = n;
c = C;
FOR(i,M){
FOA(v, B[i]){
f[v].push_back(i);
}
}
seg s;
s.build();
//s.print();
set<int> ok;
unordered_set<int> poss;
FOR(j,N-M+1){
set<int> cc = s.query(j, j+M-1);
/*cout<<j<<" "<<j+M-1<<": ";
FOA(v, cc) cout<<v<<" ";
cout<<endl;*/
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;
}
/*FOA(v, poss) cout<<v<<" ";
cout<<endl;*/
if(cc!=poss) return -1;
if(!cc.empty()){
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 |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
432 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
7 ms |
520 KB |
Output is correct |
14 |
Correct |
7 ms |
436 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
8 ms |
468 KB |
Output is correct |
18 |
Correct |
9 ms |
468 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 |
56 ms |
12620 KB |
Output is correct |
23 |
Correct |
57 ms |
12620 KB |
Output is correct |
24 |
Correct |
55 ms |
12636 KB |
Output is correct |
25 |
Correct |
18 ms |
6484 KB |
Output is correct |
26 |
Correct |
18 ms |
6484 KB |
Output is correct |
27 |
Correct |
18 ms |
5332 KB |
Output is correct |
28 |
Correct |
16 ms |
4816 KB |
Output is correct |
29 |
Correct |
15 ms |
4660 KB |
Output is correct |
30 |
Correct |
16 ms |
4660 KB |
Output is correct |
31 |
Execution timed out |
1593 ms |
8416 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
308 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
432 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
7 ms |
520 KB |
Output is correct |
14 |
Correct |
7 ms |
436 KB |
Output is correct |
15 |
Correct |
6 ms |
468 KB |
Output is correct |
16 |
Correct |
7 ms |
468 KB |
Output is correct |
17 |
Correct |
8 ms |
468 KB |
Output is correct |
18 |
Correct |
9 ms |
468 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 |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
23 ms |
1200 KB |
Output is correct |
29 |
Correct |
3 ms |
596 KB |
Output is correct |
30 |
Correct |
3 ms |
556 KB |
Output is correct |
31 |
Correct |
3 ms |
724 KB |
Output is correct |
32 |
Correct |
3 ms |
596 KB |
Output is correct |
33 |
Correct |
5 ms |
432 KB |
Output is correct |
34 |
Correct |
6 ms |
468 KB |
Output is correct |
35 |
Correct |
2 ms |
340 KB |
Output is correct |
36 |
Correct |
4 ms |
432 KB |
Output is correct |
37 |
Correct |
3 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
468 KB |
Output is correct |
41 |
Correct |
4 ms |
424 KB |
Output is correct |
42 |
Correct |
2 ms |
468 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
45 ms |
1848 KB |
Output is correct |
46 |
Correct |
6 ms |
980 KB |
Output is correct |
47 |
Correct |
5 ms |
884 KB |
Output is correct |
48 |
Correct |
5 ms |
680 KB |
Output is correct |
49 |
Correct |
4 ms |
736 KB |
Output is correct |
50 |
Correct |
7 ms |
468 KB |
Output is correct |
51 |
Correct |
7 ms |
520 KB |
Output is correct |
52 |
Correct |
7 ms |
468 KB |
Output is correct |
53 |
Correct |
7 ms |
468 KB |
Output is correct |
54 |
Correct |
7 ms |
524 KB |
Output is correct |
55 |
Correct |
9 ms |
524 KB |
Output is correct |
56 |
Correct |
4 ms |
564 KB |
Output is correct |
57 |
Correct |
7 ms |
528 KB |
Output is correct |
58 |
Correct |
3 ms |
468 KB |
Output is correct |
59 |
Correct |
7 ms |
468 KB |
Output is correct |
60 |
Correct |
3 ms |
560 KB |
Output is correct |
61 |
Correct |
7 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
520 KB |
Output is correct |
16 |
Correct |
7 ms |
436 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
8 ms |
468 KB |
Output is correct |
20 |
Correct |
9 ms |
468 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 |
56 ms |
12620 KB |
Output is correct |
25 |
Correct |
57 ms |
12620 KB |
Output is correct |
26 |
Correct |
55 ms |
12636 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
23 ms |
1200 KB |
Output is correct |
32 |
Correct |
3 ms |
596 KB |
Output is correct |
33 |
Correct |
3 ms |
556 KB |
Output is correct |
34 |
Correct |
3 ms |
724 KB |
Output is correct |
35 |
Correct |
3 ms |
596 KB |
Output is correct |
36 |
Correct |
5 ms |
432 KB |
Output is correct |
37 |
Correct |
6 ms |
468 KB |
Output is correct |
38 |
Correct |
2 ms |
340 KB |
Output is correct |
39 |
Correct |
4 ms |
432 KB |
Output is correct |
40 |
Correct |
3 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
468 KB |
Output is correct |
44 |
Correct |
4 ms |
424 KB |
Output is correct |
45 |
Correct |
2 ms |
468 KB |
Output is correct |
46 |
Correct |
2 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
45 ms |
1848 KB |
Output is correct |
49 |
Correct |
6 ms |
980 KB |
Output is correct |
50 |
Correct |
5 ms |
884 KB |
Output is correct |
51 |
Correct |
5 ms |
680 KB |
Output is correct |
52 |
Correct |
4 ms |
736 KB |
Output is correct |
53 |
Correct |
7 ms |
468 KB |
Output is correct |
54 |
Correct |
7 ms |
520 KB |
Output is correct |
55 |
Correct |
7 ms |
468 KB |
Output is correct |
56 |
Correct |
7 ms |
468 KB |
Output is correct |
57 |
Correct |
7 ms |
524 KB |
Output is correct |
58 |
Correct |
9 ms |
524 KB |
Output is correct |
59 |
Correct |
4 ms |
564 KB |
Output is correct |
60 |
Correct |
7 ms |
528 KB |
Output is correct |
61 |
Correct |
3 ms |
468 KB |
Output is correct |
62 |
Correct |
7 ms |
468 KB |
Output is correct |
63 |
Correct |
3 ms |
560 KB |
Output is correct |
64 |
Correct |
7 ms |
468 KB |
Output is correct |
65 |
Correct |
290 ms |
4828 KB |
Output is correct |
66 |
Correct |
75 ms |
2304 KB |
Output is correct |
67 |
Correct |
604 ms |
6124 KB |
Output is correct |
68 |
Correct |
233 ms |
3716 KB |
Output is correct |
69 |
Correct |
500 ms |
5400 KB |
Output is correct |
70 |
Correct |
59 ms |
1600 KB |
Output is correct |
71 |
Correct |
68 ms |
1820 KB |
Output is correct |
72 |
Correct |
60 ms |
1628 KB |
Output is correct |
73 |
Correct |
11 ms |
1108 KB |
Output is correct |
74 |
Correct |
53 ms |
1600 KB |
Output is correct |
75 |
Correct |
39 ms |
1364 KB |
Output is correct |
76 |
Correct |
38 ms |
8028 KB |
Output is correct |
77 |
Correct |
32 ms |
9372 KB |
Output is correct |
78 |
Correct |
44 ms |
10552 KB |
Output is correct |
79 |
Correct |
1347 ms |
9860 KB |
Output is correct |
80 |
Correct |
1369 ms |
9860 KB |
Output is correct |
81 |
Correct |
1371 ms |
9864 KB |
Output is correct |
82 |
Correct |
1366 ms |
10136 KB |
Output is correct |
83 |
Correct |
1435 ms |
9996 KB |
Output is correct |
84 |
Correct |
96 ms |
2004 KB |
Output is correct |
85 |
Correct |
93 ms |
2020 KB |
Output is correct |
86 |
Correct |
94 ms |
2012 KB |
Output is correct |
87 |
Correct |
94 ms |
2020 KB |
Output is correct |
88 |
Correct |
91 ms |
2012 KB |
Output is correct |
89 |
Correct |
104 ms |
2004 KB |
Output is correct |
90 |
Correct |
68 ms |
11244 KB |
Output is correct |
91 |
Correct |
71 ms |
11212 KB |
Output is correct |
92 |
Correct |
66 ms |
11232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
520 KB |
Output is correct |
16 |
Correct |
7 ms |
436 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
8 ms |
468 KB |
Output is correct |
20 |
Correct |
9 ms |
468 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 |
56 ms |
12620 KB |
Output is correct |
25 |
Correct |
57 ms |
12620 KB |
Output is correct |
26 |
Correct |
55 ms |
12636 KB |
Output is correct |
27 |
Correct |
18 ms |
6484 KB |
Output is correct |
28 |
Correct |
18 ms |
6484 KB |
Output is correct |
29 |
Correct |
18 ms |
5332 KB |
Output is correct |
30 |
Correct |
16 ms |
4816 KB |
Output is correct |
31 |
Correct |
15 ms |
4660 KB |
Output is correct |
32 |
Correct |
16 ms |
4660 KB |
Output is correct |
33 |
Execution timed out |
1593 ms |
8416 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
308 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
432 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
7 ms |
520 KB |
Output is correct |
16 |
Correct |
7 ms |
436 KB |
Output is correct |
17 |
Correct |
6 ms |
468 KB |
Output is correct |
18 |
Correct |
7 ms |
468 KB |
Output is correct |
19 |
Correct |
8 ms |
468 KB |
Output is correct |
20 |
Correct |
9 ms |
468 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 |
56 ms |
12620 KB |
Output is correct |
25 |
Correct |
57 ms |
12620 KB |
Output is correct |
26 |
Correct |
55 ms |
12636 KB |
Output is correct |
27 |
Correct |
18 ms |
6484 KB |
Output is correct |
28 |
Correct |
18 ms |
6484 KB |
Output is correct |
29 |
Correct |
18 ms |
5332 KB |
Output is correct |
30 |
Correct |
16 ms |
4816 KB |
Output is correct |
31 |
Correct |
15 ms |
4660 KB |
Output is correct |
32 |
Correct |
16 ms |
4660 KB |
Output is correct |
33 |
Execution timed out |
1593 ms |
8416 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |