# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
735376 | keisuke6 | Painting Walls (APIO20_paint) | C++14 | 0 ms | 0 KiB |
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>
using namespace std;
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector<vector<int>> B){
map<int,int> m;// c, p
vector<int> A(N);
for(int i=0;i<M;i++){
for(int x:B[i]){
m[x] = i;
}
}
for(int i=0;i<N;i++) A[i] = m[C[i]];
int ans = 1;
for(int i=1;i<N;i++){
if((A[i-1]+1)%M != A[i]){
ans++;
if(N-M < i) return -1;
}
}
return ans;
}