Submission #961973

#TimeUsernameProblemLanguageResultExecution timeMemory
961973Mohamed_Kachef06Painting Walls (APIO20_paint)C++17
28 / 100
1579 ms7760 KiB
#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) return 0; 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); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...