# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
908490 | Itamar | Painting Walls (APIO20_paint) | C++14 | 647 ms | 14580 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"
using namespace std;
#include <vector>
#define vi vector<int>
int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) {
int ans = 0;
vector<bool> dp(N);
int sum = 0;
vi g(M);
vector<vi> fr(K);
for (int i = 0; i < M; i++) {
for (int j = 0; j < A[i]; j++) {
fr[B[i][j]].push_back(i);
}
}
for (int i = N - M; i < N; i++) {
for (int j : fr[C[i]]) {
g[(M+i-j)%M]++;
if (g[(M+i - j) % M] == M)sum++;
}
}
dp[N - M] = (sum > 0);
for (int i = N - M-1; i >= 0; i--) {
for (int j : fr[C[i]]) {
g[(M + i - j) % M]++;
if (g[(M + i - j) % M] == M)sum++;
}
for (int j : fr[C[M+i]]) {
g[(M + i - j) % M]--;
if (g[(M + i - j) % M] == M-1)sum--;
}
dp[i] = (sum>0);
}
int maxi = -1, nex = 0;
for (int i = 0; i <= N - M; i++) {
if (dp[i])maxi = i + M - 1;
if (i == N - M) {
if (maxi == N-1)return ans + 1;
return -1;
}
if (i == nex) {
if (maxi < i)return -1;
nex = maxi+1;
maxi = -1;
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... |