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 <vector>
#include <bits/stdc++.h>
using namespace std;
int minimumInstructions(int N,int M,int K,vector <int> C,vector <int> A,vector <vector <int> > B){
vector <int> suit[K];
for (int i=0; i<K; i++) suit[i].clear();
for (int i=0; i<M; i++){
for (int j:B[i]) suit[j].push_back(i);
}
bool ok[N];
int freq[M];
for (int i=0; i<M; i++) freq[i]=0;
for (int i=0; i+M-1<N; i++){
if (i){
for (int j:suit[C[i-1]]){
int ths=j-(i-1);
ths%=M; ths+=M; ths%=M;
freq[ths]--;
}
} else {
for (int idx=0; idx<M-1; idx++){
for (int j:suit[C[idx]]){
int ths=j-idx;
ths%=M; ths+=M; ths%=M;
freq[ths]++;
}
}
}
ok[i]=0;
int idx=i+M-1;
for (int j:suit[C[idx]]){
int ths=j-idx;
ths%=M; ths+=M; ths%=M;
freq[ths]++;
if (freq[ths]==M) ok[i]=1;
}
}
int lst[N];
for (int i=0; i<N; i++){
if (ok[i]) lst[i]=i;
else lst[i]=-1;
}
for (int i=1; i<N; i++) lst[i]=max(lst[i],lst[i-1]);
if (lst[0]==-1) return -1;
int cnt=1,cur=0;
while (cur+M-1<N-1){
if (lst[cur+M]<=cur) return -1;
cur=max(cur,lst[cur+M]);
cnt++;
}
return cnt;
}
# | 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... |