Submission #566188

#TimeUsernameProblemLanguageResultExecution timeMemory
566188hollwo_pelwPainting Walls (APIO20_paint)C++17
100 / 100
1279 ms262768 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>> pos(K), pos_ok(M); vector<int> ok, vis(N); for (int i = 0; i < M; i++) { for (int col : B[i]) pos[col].push_back(i); } for (int i = 0; i < N; i++) { if (C[i] >= K || C[i] < 0) continue; for (int j : pos[C[i]]) pos_ok[((j - i) % M + M) % M].push_back(i); } for (int i = 0; i < M; i++) { for (int l = 0, r = M - 1; r < (int) pos_ok[i].size(); l ++, r ++) { if (pos_ok[i][r] - pos_ok[i][l] + 1 == M) vis[pos_ok[i][l]] = 1; } } for (int i = 0; i < N; i++) if (vis[i]) ok.push_back(i); ok.push_back(N); int res = 0, p = 0; if (!vis[0]) return -1; for (int np; p < N; res ++, p = np) { if (p == (np = *prev(upper_bound(ok.begin(), ok.end(), p + M)))) return -1; } return res; }
#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...