제출 #391943

#제출 시각아이디문제언어결과실행 시간메모리
391943MrDomino벽 칠하기 (APIO20_paint)C++14
28 / 100
1581 ms12036 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; int sum(int a, int b) { return a * b; } const int INF = (int) 1e9; int minimumInstructions(int n, int m, int k, vector<int> c, vector<int> sizes, vector<vector<int>> b) { vector<int> can(n, 0); vector<vector<int>> guys(k); for (int i = 0; i < m; i++) { for (auto &j : b[i]) { guys[j].push_back(i); } } deque<int> dq; for (int raz = 0; raz < m; raz++) { for (int i = 0; i + m - 1 < n; i++) { if (can[i]) { continue; } can[i] = 1; for (int j = 0; j < m; j++) { can[i] = 0; for (auto &x : guys[c[i + j]]) { if ((x - j + m) % m == raz) { can[i] = 1; break; } } if (!can[i]) { break; } } } } { /// shift can by 1 reverse(can.begin(), can.end()); can.push_back(0); reverse(can.begin(), can.end()); } vector<int> dp(n + 1, INF); dp[0] = 0; dq.clear(); dq.push_back(0); for (int i = m; i <= n; i++) { /// finish at position i => I've started at position i-k+1 int start = i - m + 1; if (!can[start]) { continue; } while (!dq.empty() && dq.front() < start - 1) { dq.pop_front(); } while (!dq.empty() && dp[i] <= dp[dq.back()]) { dq.pop_back(); } if (!dq.empty()) { dp[i] = dp[dq.front()] + 1; } dq.push_back(i); } if (dp[n] == INF) { dp[n] = -1; } return dp[n]; }
#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...