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"
using namespace std;
vector<int> vals[100001];
int minimumInstructions(int n , int m , int K , vector<int> c , vector<int> A , vector<vector<int>> B){
for(int i = 0 ; i < m ; i += 1){
for(auto j : B[i]){
vals[j].push_back(i);
}
}
vector<pair<int,pair<int,int>>> q,q2;
for(int i : vals[c[0]]){
q.push_back({i,{1,1}});
}
for(int i = 1 ; i < n ; i += 1){
q2.clear();
int mini = 1000000000;
for(auto j : q){
mini = min(mini,j.second.second);
if(j.second.first == m){
continue;
}
if(*lower_bound(vals[c[i]].begin(),vals[c[i]].end(),(j.first+1)%m) == (j.first+1)%m){
q2.push_back({(j.first+1)%m,{j.second.first+1,j.second.second}});
}
}
for(auto j : vals[c[i]]){
q2.push_back({j,{1,mini+1}});
}
swap(q,q2);
}
int mini = 1000000000;
for(auto i : q){
if(i.second.first == m){
mini = min(mini,i.second.second);
}
}
if(mini == 1000000000){
return -1;
}
return mini;
}
# | 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... |