This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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/2);
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(i+M-1<nax/2) {
if(is[i+M-1][pre_tag]) {
cur_succ = j;
break;
} else continue;
} else {
if(binary_search(cand[i+M-1].begin(), cand[i+M-1].end(), 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;
if(i+l<nax/2) yasss &= is[i+l][cr];
else yasss &= binary_search(cand[i+l].begin(), cand[i+l].end(), 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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |