제출 #566185

#제출 시각아이디문제언어결과실행 시간메모리
566185hollwo_pelw벽 칠하기 (APIO20_paint)C++17
0 / 100
0 ms212 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; 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) ok.push_back(pos_ok[i][l]); } } ok.push_back(N); sort(ok.begin(), ok.end()); ok.erase(unique(ok.begin(), ok.end()), ok.end()); int res = 0, p = 0; if (ok[0] == 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...