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 <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<vector<int> > colors(K);
for(int i = 0; i < M; i++)
for(int& a : B[i]) colors[a].push_back(i);
int ans = 0, last = -3, l = M;
for(int i = 0; i < N; i++){
if(colors[C[i]].empty()) return -1;
if(colors[C[i]][0] != (last+1)%M){
if(l < M) return -1;
ans++, l = 1;
}
else{
if(++l%M == 1) ans++;
}
}
if(l < M) 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... |