#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int nax = 1e5;
vector<int> col_to_wall[nax], cand[nax];
vector<bitset<nax/2>>is(nax);
bool good[nax];
bool on[nax];
int minimumInstructions(
int N, int M, int K, vector<int> C,
vector<int> A, vector<vector<int>> B) {
for(int i=0; i<N; ++i) {
col_to_wall[C[i]].push_back(i);
}
for(int i=0; i<M; ++i) {
for(int j=0; j<A[i]; ++j) {
for(int x : col_to_wall[B[i][j]]) {
cand[x].push_back(i);
is[x][i] = 1;
}
}
}
int prev_succ = -1;
for(int i=0; i<=N-M; ++i) {
int cur_succ = -1;
for(int j : cand[i]) {
int pre_tag = (j-1+M)%M;
bool yasss = true;
if(pre_tag==prev_succ) {
if(is[i+M-1][pre_tag]) {
cur_succ = j;
break;
} else {
continue;
}
} else if(on[pre_tag]) {
continue;
}
for(int l=1, cr=j+1; l<M; ++l, ++cr) {
if(cr==M) cr = 0;
yasss &= is[i+l][cr];
if(!yasss) break;
}
if(yasss) {
cur_succ = j;
break;
}
}
if(i) {
for(int x : cand[i-1]) {
if(x==prev_succ) break;
on[x] = 0;
}
}
for(int x : cand[i]) {
if(x==cur_succ) break;
on[x] = 1;
}
prev_succ = cur_succ;
if(cur_succ!=-1) {
good[i] = 1;
}
}
if(!good[0]) return -1;
int last = 0, pending = -1;
int ans = 1;
for(int i=1; i<N; ++i) {
if(good[i]) {
pending = i;
}
if(last+M==i) {
if(pending==-1) return -1;
last = pending;
pending = -1;
++ans;
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
272 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
272 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
272 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
272 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
272 ms |
524288 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |