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;
const int maxn=100000+10;
int n,m,k;
vector<int>allk[maxn];
int len[maxn],last[maxn],fakelast[maxn],fakelen[maxn];
int minimumInstructions(int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
n=N;
m=M;
k=K;
for(int i=0;i<m;i++){
for(auto x:B[i]){
allk[x].push_back(i);
}
}
vector<int>res(n+2);
for(int i=0;i<maxn;i++){
last[i]=n;
}
for(int i=n-1;i>=0;i--){
for(auto x:allk[C[i]]){
fakelast[x]=i;
if(last[(x+1)%m]!=i+1){
fakelen[x]=1;
}else{
fakelen[x]=min(m,fakelen[(x+1)%m]+1);
}
}
for(auto x:allk[C[i]]){
last[x]=fakelast[x];
len[x]=fakelen[x];
if(len[x]==m){
res[i]=1;
}
}
}
int ted=0;
if(res[0]==0){
return -1;
}
int mx=-1,fakemx=-1;
while(mx!=n-1){
// cout<<mx<<" "<<fakemx<<endl;
ted++;
fakemx=max(fakemx,res[mx+1]*m+mx);
if(fakemx==mx){
return -1;
}
int j=mx;
mx=fakemx;
for(;j<=mx;j++){
fakemx=max(fakemx,res[j+1]*m+j);
}
}
return ted;
}
# | 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... |