# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
558701 | Ai7081 | Painting Walls (APIO20_paint) | C++17 | 1095 ms | 14924 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "paint.h"
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B)
{
vector<int> col[K+5];
for (int i=0; i<B.size(); i++) for (auto it : B[i]) col[it].push_back(i);
vector<int> dp(N+5, inf);
vector<int> cnt(M+5, 0);
deque<pair<int, int>> dq;
int n_good = 0;
for (int i=0; i<N; i++) {
if (i >= M) {
for (auto j : col[C[i-M]]) n_good -= (cnt[(N+j-i)%M]-- == M);
}
for (auto j : col[C[i]]) n_good += (++cnt[(N+j-i)%M] == M);
if (n_good) {
if (i == M-1) dp[i] = 1;
else {
while (!dq.empty() && dq.front().second < i-M) dq.pop_front();
if (!dq.empty()) dp[i] = dq.front().first + 1;
}
while (!dq.empty() && dq.back().first >= dp[i]) dq.pop_back();
dq.push_back({dp[i], i});
}
}
return (dp[N-1] < inf ? dp[N-1] : -1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |