Submission #391957

#TimeUsernameProblemLanguageResultExecution timeMemory
391957MrDominoPainting Walls (APIO20_paint)C++14
28 / 100
1571 ms6544 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++) { vector<int> acum(n, 0); for (int i = 0; i + m - 1 < n; i++) { acum[i] = 1; } for (int sum = 0; sum < n; sum++) { for (int j = 0; j < m && j <= sum; j++) { int i = sum - j; if (0 <= i && i + m - 1 < n) { } else { continue; } assert(0 <= i && i + m - 1 < n); bool ok = 0; for (auto &x : guys[c[i + j]]) { if (x == (raz + j) % m) { ok = 1; break; } } if (!ok) { acum[i] = 0; } } } for (int i = 0; i < n; i++) { can[i] |= acum[i]; } } { /// 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...