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 <algorithm>
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) x.begin(),x.end();
using ll=long long;
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
vector<vector<int>> cols(K);
rep(i,M){
for(int j:B[i]){
cols[j].emplace_back(i);
}
}
int ans=0;
int cnt=0;
vector<int> can;
rep(i,N){
if(!can.empty()){
vector<int> nxt;
for(int j:can){
int now=(j+1)%M;
if(*lower_bound(B[now].begin(),B[now].end(),C[i])==C[i]){
nxt.emplace_back(now);
}
}
swap(can,nxt);
if(can.empty()){
if(ans==0){
return -1;
}
cnt=0;
ans++;
can.clear();
}
}
if(cnt==0){
can=cols[C[i]];
}
cnt++;
if(cnt==M){
cnt=0;
ans++;
can.clear();
}
}
if(cnt!=0)ans++;
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... |