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;
#include "paint.h"
#define V vector
int minimumInstructions(int N, int M, int K, V<int> C, V<int> A, V<V<int>> B) {
V<int> cand[K], x(M), y(M), dp(N+1);
for(int i = 0; i < M; i++)
for(int &j : B[i]) cand[j].push_back(i);
for(int i = N; --i >= 0; swap(x, y)) {
if(i+2 < N)
for(int j : cand[C[i+2]]) x[j] = 0;
for(int j : cand[C[i]])
if((x[j] = 1 + y[(j + 1) % M]) >= M) dp[i] = 1;
}
int ans = 0; dp[N] = dp[0];
for(int i = 0, j; i < N; i = j, ans++) {
j = min(N, i + M);
while(j > i && !dp[j]) --j;
if(i == j) return -1;
}
return ans;
}
# | 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... |