Submission #429893

#TimeUsernameProblemLanguageResultExecution timeMemory
429893SundavarPainting Walls (APIO20_paint)C++14
0 / 100
1 ms204 KiB
#include "paint.h" #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<vector<int> > colors(K); for(int i = 0; i < M; i++) for(int& a : B[i]) colors[a].push_back(i); map<int,int> last; vector<bool> start(N, false); for(int i = 0; i < N; i++){ map<int,int> uj; for(int& a : colors[C[i]]){ if(last.count((a+M-1)%M) > 0) uj[a] = 1 + last[(a+M-1)]; else uj[a] = 1; } for(auto it = uj.begin(); it != uj.end(); it++) if(it->second >= M) start[i-M+1] = true; last = uj; } vector<int> best(N, -1e9); for(int i = 0; i < N; i++) best[i] = max((i > 0 ? best[i-1] : -1e9), (start[i] ? i : -1e9)); int poz = 0, ans = 0; while(poz < N){ if(poz - best[poz] >= M) return -1; poz = best[poz]+M, 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...