Submission #965936

#TimeUsernameProblemLanguageResultExecution timeMemory
965936willychanPainting Walls (APIO20_paint)C++17
0 / 100
1 ms348 KiB
#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)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:46:7: warning: unused variable 'cur' [-Wunused-variable]
   46 |   int cur = 0;
      |       ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...