# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
961969 | Mohamed_Kachef06 | Painting Walls (APIO20_paint) | C++17 | 0 ms | 0 KiB |
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 "grader.cpp"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
bool poss[400'001];
int dp[100'001];
int n , m , k ;
int brute(int i){
if (i == n-1) return 0;
else if (i >= n) return 1e9;
if (~dp[i]) return dp[i];
int ans = 1e9;
if (poss[i]){
for (int j = i+1 ; j <= i+m ; j++) ans = min(ans , brute(j) + 1);
}
return dp[i] = ans;
}
int minimumInstructions(
int N, int M, int K, std::vector<int> C,
std::vector<int> A, std::vector<std::vector<int>> B) {
n = N; m = M; k = K;
// N number of segments
// M number of contractors
// C(n) the intended color for each segment
// A(m) the number of colors each contractor likes
// B(m) the set of colors each contractor likes
for (auto &i : B ) sort(i.begin() , i.end());
for (int y = 0; y <= N-M ; y++){
for (int x = 0 ; x < M ; x++){
bool f = 1;
for (int l = 0 ; l < M ; l++){
int cont = (x+l)%M ;
if (!binary_search(B[cont].begin() , B[cont].end() , C[y+l])) {f = 0; break;}
}
if (f) {poss[y] = 1; break; }
}
}
memset(dp , -1 , sizeof dp);
int ans = brute(0);
return (ans == 1e9 ? -1 : ans);
}