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> g[K], x(M), y(M), dp(N+1);
int ans = 0, i = M, j;
while(--i >= 0) for(int &s : B[i]) g[s].push_back(i);
for(i = N; --i >= 0; x.swap(y)) {
if(i+2 < N) for(int s : g[C[i+2]]) x[s] = 0;
for(int s : g[C[i]]) if((x[s] = 1 + y[(s + 1) % M]) >= M) dp[i] = 1;
}
for(dp[N] = dp[i=0]; i < N; i = j, ans++) {
for(j = min(N, i+M); 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... |