# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289214 | dolphingarlic | Painting Walls (APIO20_paint) | C++14 | 547 ms | 12944 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;
int dp[2][50002];
vector<int> good[100002];
bool possible[100002];
int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) {
for (int i = 0; i < M; i++) for (int j : B[i]) good[j].push_back(i);
for (int i = N - 1; ~i; i--) {
for (int j : good[C[i + 2]]) dp[i & 1][j] = 0;
for (int j : good[C[i]]) {
dp[i & 1][j] = dp[i + 1 & 1][(j + 1) % M] + 1;
if (dp[i & 1][j] >= M) possible[i] = true;
}
}
int ans = 0, last_painted = -1;
for (int i = 0, best = -M; i < N; i++) {
if (possible[i]) best = i;
if (i > last_painted) {
if (best + M == i) return -1;
ans++;
last_painted = best + M - 1;
}
}
return ans;
}
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... |