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 "paint.h"
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B){
vector<vector<int>> G(N+1);
vector<set<int>> S(M);
for(int i=0;i<M;i++)for(int x:B[i]) S[i].insert(x);
for(int i=0;i<=N-M;i++){
bool ok = false;
for(int j=0;j<M;j++){
if(ok) break;
bool now = true;
for(int k=i;k<i+M;k++){
if(!S[(j+k-i)%M].count(C[k])) now = false;
}
if(now) ok = true;
}
if(ok){
for(int j=i+1;j<=i+M;j++) G[i].push_back(j);
}
}
queue<int> q;
q.push(0);
vector<int> dist(N+1,1e9);
dist[0] = 0;
while(!q.empty()){
int pos = q.front();
q.pop();
for(int x:G[pos]){
if(dist[x] != 1e9) continue;
dist[x] = dist[pos] + 1;
q.push(x);
}
}
if(dist[N] == 1e9) return -1;
else return dist[N];
}
# | 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... |