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 N=100005;
int dp[N];
vector<int> col[N];
int minimumInstructions(int n, int m, int K, vector<int> v, vector<int> A, vector<vector<int>> a) {
for(int i=0;i<=n;i++) dp[i]=1e9;
for(int i=0;i<m;i++){
for(auto j:a[i]){
col[j].push_back(i);
}
}
dp[0]=0;
for(int i=0;i<=n-m;i++){
bool flag=1;
for(auto ii:col[v[i]]){
flag=0; int j=ii;
for(int cnt=0;cnt<m;cnt++){
if(!binary_search(col[v[i+cnt]].begin(),col[v[i+cnt]].end(),j)) flag=1;
if(flag) break;
j++; j%=m;
}
if(!flag) break;
}
if(!flag){
for(int j=1;j<=m;j++) dp[i+j]=min(dp[i]+1,dp[i+j]);
}
}
if(dp[n]>=1e9) return -1;
return dp[n];
}
# | 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... |