Submission #737639

#TimeUsernameProblemLanguageResultExecution timeMemory
737639Abrar_Al_SamitPainting Walls (APIO20_paint)C++17
63 / 100
1578 ms158300 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; const int nax = 1e5 + 3; vector<int> col_to_wall[nax], cand[nax]; bool good[nax]; bool on[nax]; int minimumInstructions( int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { for(int i=0; i<N; ++i) { col_to_wall[C[i]].push_back(i); } for(int i=0; i<M; ++i) { for(int j=0; j<A[i]; ++j) { for(int x : col_to_wall[B[i][j]]) { cand[x].push_back(i); } } } int prev_succ = -1; for(int i=0; i<=N-M; ++i) { int cur_succ = -1; for(int j : cand[i]) { int pre_tag = (j-1+M)%M; bool yasss = true; if(pre_tag==prev_succ) { if(binary_search(cand[i+M-1].begin(), cand[i+M-1].end(), pre_tag)) { cur_succ = j; break; } else { continue; } } else if(on[pre_tag]) { continue; } for(int l=0, cr=j; l<M; ++l, ++cr) { if(cr==M) cr = 0; yasss &= binary_search(cand[i+l].begin(), cand[i+l].end(), cr); if(!yasss) break; } if(yasss) { cur_succ = j; break; } } if(i) { for(int x : cand[i-1]) { if(x==prev_succ) break; on[x] = 0; } } for(int x : cand[i]) { if(x==cur_succ) break; on[x] = 1; } prev_succ = cur_succ; if(cur_succ!=-1) { good[i] = 1; } } if(!good[0]) return -1; int last = 0, pending = -1; int ans = 1; for(int i=1; i<N; ++i) { if(good[i]) { pending = i; } if(last+M==i) { if(pending==-1) return -1; last = pending; pending = -1; ++ans; } } return ans; }
#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...