# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
402937 | proma | Painting Walls (APIO20_paint) | C++17 | 1 ms | 204 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 <bits/stdc++.h>
using namespace std;
int minimumInstructions (int N, int M, int K, vector <int> C, vector<int> A, vector <vector<int>> B) {
vector <int> contractor[N];
for (int i = 0; i < M; i ++) {
for (int j = 0; j < A[i]; j ++) {
contractor[B[i][j]].push_back(i);
}
}
int dp[2][M], mx[N];
memset(dp, 0, sizeof(dp));
memset(mx, 0, sizeof(mx));
for (auto i: contractor[0]) {
dp[0][i] = 1;
}
for (int i = 1; i < N; i ++) {
for (auto j: contractor[C[i]]) {
dp[i & 1][j] = min(dp[!(i & 1)][(j - 1 + M) % M] + 1, M);
mx[i] = max(mx[i], dp[i & 1][j]);
}
for (auto j: contractor[C[i-1]]) {
dp[!(i & 1)][j] = 0;
}
}
if (mx[N - 1] != M) {
return -1;
}
int last, cnt = M - 1, flag = 1, ans = 1;
for (int i = N - 2; i >= 0; i --, cnt --) {
if (mx[i] == M) {
last = i;
flag = 0;
}
if (!cnt) {
if (flag) {
return -1;
}
flag = 1;
cnt = M - last + i + 1;
ans ++;
}
}
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... |