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"
//#include "grader.cpp"
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) x.begin(),x.end()
#define pb push_back
int minimumInstructions(int N, int M, int K, vi C,vi A, vvi B) {
vvi who(K);
for(int i=0; i<N;i++)
for(int j=0; j<A[i]; j++)
who[B[i][j]].pb(i);
for(int i=0; i<N; i++)
sort(all(B[i]));
vvi can(N,vi(M));// iff a sequence from j can start in i
for(int i=0; i+M<=N;i++){
for(int j=0; j<M; j++){
can[i][j]=M;
for(int j2=0; j2<M; j2++)
if(!binary_search(all(B[(j+j2)%M]),C[(i+j2)])){
can[i][j] = 0;
break;
}
}
}
set<int>segs;
for(int i=0; i<N; i++)
for(int j=0; j<M; j++)
if(can[i][j]==M)
segs.insert(i);
int ans=0;
vector<bool>cov(N);
for(int i=0; i<N;i++){
if(cov[i])continue;
int l=-1;
for(int j=0;i-j>=0 && j<M; j++)
if(segs.count(i-j)) {
l = i - j;
break;
}
if(l==-1)return -1;
for(int j=l; j<l+M; j++)
cov[j]=1;
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... |