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<bits/stdc++.h>
#include "paint.h"
#define MAXN 100007
using namespace std;
int n,m,k,ans;
int c[MAXN];
vector<int> cols[MAXN];
bool can[20007][2007];
int to[2][2007];
int best[MAXN],pref[MAXN];
int minimumInstructions(int N, int M, int K, vector<int> C,vector<int> A, vector< vector<int> > B) {
n=N; m=M; k=K;
for(int i=1;i<=n;i++){
c[i]=C[i-1];
}
for(int i=1;i<=m;i++){
cols[i]=B[i-1];
}
for(int i=1;i<=n;i++){
for(int f=1;f<=m;f++){
for(int s:cols[f]){
if(s==c[i])can[i][f]=true;
}
}
}
for(int i=n;i>=1;i--){
for(int f=1;f<=m;f++){
if(!can[i][f])to[i%2][f]=0;
else{
if(f<m)to[i%2][f]=to[1-i%2][f+1]+1;
else to[i%2][f]=to[1-i%2][1]+1;
}
if(to[i%2][f]>=m)best[i]=max(best[i],i+m);
}
}
for(int i=1;i<=n;i++){
pref[i]=max(pref[i-1],best[i]);
}
int pos=1;
while(pos<=n){
if(pref[pos]<=pos)return -1;
pos=pref[pos];
ans++;
}
return ans;
}
/*
int main(){
//cout<<minimumInstructions(8, 3, 5, {3, 3, 1, 3, 4, 4, 2, 2}, {3, 2, 2}, {{0, 1, 2}, {2, 3}, {3, 4}});
cout<<minimumInstructions(5, 4, 4, {1, 0, 1, 2, 2}, {2, 1, 1, 1}, {{0, 1}, {1}, {2}, {3}});
return 0;
}
*/
# | 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... |