# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
558696 | Ai7081 | Painting Walls (APIO20_paint) | C++17 | 1 ms | 304 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 bool debug = 0;
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[(M+(j-(i-M))%M)%M]-- == M);
}
for (auto j : col[C[i]]) n_good += (++cnt[(M+(j-i)%M)%M] == M);
if (n_good) {
if (i == M-1) dp[i] = 1;
else {
while (!dq.empty() && dq.front().second < i-M) dq.pop_front();
dp[i] = dq.front().first + 1;
}
while (!dq.empty() && dq.back().first >= dp[i]) dq.pop_back();
dq.push_back({dp[i], i});
}
}
if (debug) {
printf("dp : ");
for (int i=0; i<N; i++) printf("%d ", dp[i]);
printf("\n");
}
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... |