# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
965936 | willychan | Painting Walls (APIO20_paint) | C++17 | 1 ms | 348 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>
using namespace std;
typedef long long ll;
int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) {
vector<int> ok(N,0);
vector<int> mp(K,-1);
for(int i=0;i<M;i++){
for(int j=0;j<A[i];j++) {
mp[B[i][j]]=i;
}
}
for(int i=0;i<N;i++){
C[i] = mp[C[i]];
}
vector<int> gnext(N-1,0);
for(int i=0;i<N-1;i++) {
gnext[i] = (C[i]+1)%M==C[i+1];
}
int head = 0;
int ocnt=0;
for(int i=0;i<=N-M;i++){
while(head<=i+M-2){
ocnt+=(gnext[head]) ;
head++;
}
if(ocnt==M-1) ok[i]=1;
ocnt-=gnext[i];
}
/*
for(int i=0;i<=N-M;i++){
for(int j=0;j<M;j++){
bool work=1;
for(int k=0;k<M;k++){
int f = lower_bound(B[(j+k)%M].begin(),B[(j+k)%M].end(),C[i+k])-B[(j+k)%M].begin();
work&=(f<A[(j+k)%M] && B[(j+k)%M][f]==C[i+k]);
}
if(work){
ok[i]=1;
break;
}
}
}
*/
int cur = 0;
int ans = 0;
vector<bool> colored(N,0);
int maxn = -1e9;
for(int i=0;i<N;i++){
if(ok[i]) maxn = max(maxn,i);
if(!colored[i]){
ans++;
int k = maxn+M-1;
if(k<i) return -1;
for(int h=i;h<=k;h++) colored[h]=1;
}
}
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... |