Submission #1095979

#TimeUsernameProblemLanguageResultExecution timeMemory
1095979onlk97Painting Walls (APIO20_paint)C++14
100 / 100
497 ms14980 KiB
#include "paint.h" #include <vector> #include <bits/stdc++.h> using namespace std; int minimumInstructions(int N,int M,int K,vector <int> C,vector <int> A,vector <vector <int> > B){ vector <int> suit[K]; for (int i=0; i<K; i++) suit[i].clear(); for (int i=0; i<M; i++){ for (int j:B[i]) suit[j].push_back(i); } bool ok[N]; int freq[M]; for (int i=0; i<M; i++) freq[i]=0; for (int i=0; i+M-1<N; i++){ if (i){ for (int j:suit[C[i-1]]){ int ths=j-(i-1); ths%=M; ths+=M; ths%=M; freq[ths]--; } } else { for (int idx=0; idx<M-1; idx++){ for (int j:suit[C[idx]]){ int ths=j-idx; ths%=M; ths+=M; ths%=M; freq[ths]++; } } } ok[i]=0; int idx=i+M-1; for (int j:suit[C[idx]]){ int ths=j-idx; ths%=M; ths+=M; ths%=M; freq[ths]++; if (freq[ths]==M) ok[i]=1; } } int lst[N]; for (int i=0; i<N; i++){ if (ok[i]) lst[i]=i; else lst[i]=-1; } for (int i=1; i<N; i++) lst[i]=max(lst[i],lst[i-1]); if (lst[0]==-1) return -1; int cnt=1,cur=0; while (cur+M-1<N-1){ if (lst[cur+M]<=cur) return -1; cur=max(cur,lst[cur+M]); cnt++; } return cnt; }
#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...