# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
409846 | Ahmadsm2005 | 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 "grader.cpp"
#include <bits/stdc++.h>
using namespace std;
set<int>lolz[2001];
int minimumInstructions(int N,int M,int K,vector<int>C,vector<int>A,vector<vector<int>>B){
for(int i=0;i<B.size();i++){
for(int l=0;l<B[i].size();l++)
lolz[i].insert(B[i][l]);
}
vector<int>P;
int CUR=0,COST=0,LAST=-1;
for(int i=0;i<N-M+1;i++){
if(LAST==-1){
for(int l=0;l<M;l++){
for(int x=l;x<M+l;x++){
if(lolz[x%M].find(C[x-l+i])==lolz[x%M].end())
goto a;
}
P.push_back(i);
LAST=l;
goto b;
a:;
}
return -1;
b:;
continue;
}
LAST=(LAST+1)%M;
for(int l=LAST;l<M+LAST;l++){
if(lolz[l%M].find(C[l-LAST+i])==lolz[l%M].end())
goto c;
}
P.push_back(i);
continue;
c:;
LAST=-1;
i+=M-2;
}
if(P[0]!=0)
return -1;
int MAXER=M;
COST=1;
for(int i=1;i<P.size();i++){
if(P[i]>MAXER){
if(MAXER==P[i-1]+M)
return -1;
MAXER=P[i-1]+M;
COST++;
i--;
}
}
if(MAXER<N)
COST++;
return COST;
}