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 <iostream>
#include <vector>
#include <set>
using namespace std;
const int INF = 1e9;
int minimumInstructions(int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) {
// [y,y+M-1]
vector<set<int>> BB;
for(auto z: B) {
BB.emplace_back(set<int>(z.begin(),z.end()));
}
vector<pair<int,int>> segs;
for(int y = 0; y <= N-M; ++y){
for(int x = 0; x < M; ++x){
bool ok = true;
for(int l = 0; l < M; ++l){
if(BB[(x+l)%M].count(C[y+l]) == 0) {
ok = false;
break;
}
}
if(ok) segs.emplace_back(y,y+M-1);
}
}
vector<int> dp(N,INF);
for(auto z: segs){
int l = z.first, r = z.second;
// cerr << '[' << l << ',' << r << ']' << '\n';
if(l == 0) dp[r] = 1;
else {
for(int d = l-1; d < r; ++d){
if(dp[d] != INF) dp[r] = min(dp[d]+1,dp[r]);
}
}
}
if(dp[N-1] == INF) return -1;
else return dp[N-1];
};
# | 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... |