# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
409648 | enerelt14 | Painting Walls (APIO20_paint) | C++14 | 0 ms | 0 KiB |
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>
#include <vector>
bool is[205][100005];
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
bool ps[505];
memset(ps, 0, sizeof(ps));
memset(pos, 0, sizeof(pos));
memset(is, 0, sizeof(is));
for (int i=0;i<M;i++)for (int j=0;j<A[i];j++)is[i][B[i][j]]=1;
for (int i=0;i<N-M;i++){
for (int j=0;j<M;j++){
if (ps[i])break;
if (is[j][C[i]]){
bool x=0;
for (int l=0;l<M;l++){
if (!is[(j+l)%M][C[i+l]]){
x=1;
break;
}
}
if (!x)ps[i]=1;
}
}
}
int res=1, t=N-M;
if (!ps[t])return -1;
while(t!=0){
bool q=0;
for (int i=t-m;i<t;i++){
if (pos[i]){
t=i;
q=1;
res++;
break;
}
}
if (!q)return -1;
}
return res;
}