제출 #500904

#제출 시각아이디문제언어결과실행 시간메모리
500904sidon벽 칠하기 (APIO20_paint)C++17
63 / 100
1564 ms14052 KiB
#include <bits/stdc++.h> using namespace std; #include "paint.h" const int INF = 2e9; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { map<int, int> toR[2]; deque<int> q = {N}; vector<int> cand[K], dp(N+1, INF); dp[N] = 0; for(int i = 0; i < M; i++) for(int &j : B[i]) cand[j].push_back(i); for(int i = N; --i >= 0; ) { if(!empty(q) && q.front() > i + M) q.pop_front(); toR[i & 1].clear(); bool ok = 0; for(int j : cand[C[i]]) if((toR[i&1][j] = 1 + toR[!(i&1)][(j + 1) % M]) >= M) ok = 1; if(ok && !empty(q)) { dp[i] = 1 + dp[q.front()]; while(!empty(q) && dp[i] <= dp[q.back()]) q.pop_back(); q.push_back(i); } } return dp[0] == INF ? -1 : dp[0]; }
#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...