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>
#include "paint.h"
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int inf = 1e9 + 7;
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
for (int i = 0;i < M;++i)
sort(AI(B[i]));
vector<int> dp(N, inf);
for (int i = 0;i <= N-M;++i) {
int w = i?dp[i-1] : 0;
if (w == inf) continue;
auto valid = [&](int i, int j) {
for (int k = 0;k < M;++k) {
if (!binary_search(AI(B[(j+k)%M]), C[i+k]))
return false;
}
return true;
};
for (int j = 0;j < M;++j)
if (valid(i, j)) {
for (int k = i;k < i+M;++k)
chmin(dp[k], w + 1);
break;
}
}
return dp[N-1] == inf ? -1 : dp[N-1];
}
| # | 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... |