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];
for(int i=0; i<M; i++) for(int j:B[i]) G[j].push_back(i);
int X[M][2]{}, cnt=0, pr=-1e9, r=-1;
for(int i=0; i<N; i++) {
bool ok=0;
for(int j:G[C[i]]) ok|=(X[j][i&1]=X[(j ?: M)-1][~i&1]+1)>=M;
if(i) for(int j:G[C[i-1]]) X[j][~i&1]=0;
if(ok && i-r<=M) {
if(i-pr>M) pr=r, cnt++;
r=i;
}
}
return r==N-1 ? cnt : -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... |