Submission #304143

#TimeUsernameProblemLanguageResultExecution timeMemory
304143kkm0476Painting Walls (APIO20_paint)C++17
100 / 100
96 ms14328 KiB
#include <vector> #include <algorithm> using namespace std; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { int minimum_instructions = 0; vector<vector<int>> like(K); for(int i = 0; i < M; i++) for(int j : B[i]) like[j].push_back(i); for(int i = 0; i < N; i++) if(like[C[i]].empty()) return -1; int prev_y = -1, y = 0; while(1) { if(y < 0 || y == prev_y) return -1; bool flag = false; int max_len = 0; for(int x : like[C[y]]) { bool corr = true; for(int l = 0; l < M; l++) { if(find(like[C[y + l]].begin(), like[C[y + l]].end(), (x + l) % M) == like[C[y + l]].end()) { corr = false; max_len = max(max_len, l); break; } } if(corr) { flag = true; break; } else continue; } if(!flag) { y -= M - max_len; continue; } minimum_instructions++; prev_y = y; y += M; if(y == N) break; else y = min(y, N - M); } return minimum_instructions; }
#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...