제출 #429890

#제출 시각아이디문제언어결과실행 시간메모리
429890Sundavar벽 칠하기 (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; } 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...