# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
409952 | Carmel_Ab1 | Painting Walls (APIO20_paint) | C++17 | 1553 ms | 7824 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 <bits/stdc++.h>
#include "paint.h"
//#include "grader.cpp"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) x.begin(),x.end()
int minimumInstructions(int N, int M, int K, vi C,vi A, vvi B) {
for(int i=0; i<B.size(); i++)
sort(all(B[i]));
vector<vector<bool>>can(N,vector<bool>(M));// iff a sequence from j can start in i
for(int i=0; i+M<=N;i++){
for(int j=0; j<M; j++){
can[i][j]=1;
for(int j2=0; j2<M; j2++)
if(!binary_search(all(B[(j+j2)%M]),C[(i+j2)])) {
can[i][j] = 0;
break;
}
}
}
set<int>segs;
for(int i=0; i<N; i++)
for(int j=0; j<M; j++)
if(can[i][j])
segs.insert(i);
int ans=1;
if(*segs.begin()!=0)return -1;
int nxt=M;
while(nxt<N){
if(segs.empty())return -1;
ans++;
if(segs.count(nxt)){
segs.erase(nxt);
nxt+=M;
continue;
}
auto ub=segs.upper_bound(nxt);
if(ub==segs.begin())return -1;
ub--;
nxt=(*ub)+M;
segs.erase(*ub);
}
return ans;
}
Compilation message (stderr)
# | 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... |