Submission #402272

#TimeUsernameProblemLanguageResultExecution timeMemory
402272CollypsoPainting Walls (APIO20_paint)C++17
100 / 100
539 ms13312 KiB
#include <vector> #include <unordered_map> #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() using namespace std; int minimumInstructions(int N, int M, int K, vt<int> C, vt<int> A, vt<vt<int>> B) { vt<vt<int>> master(K); for(int i = 0; i < M; i++) for(int j = 0; j < A[i]; j++) master[B[i][j]].pb(i); vt<vt<int>> dp(2, vt<int>(M)); vt<int> dpMax(N); dpMax[0] = 1; for(int m : master[C[0]]) dp[0][m] = 1; for(int i = 1; i < N; i++) { for(int m : master[C[i]]) { int len = min(M, dp[!(i & 1)][(m + M - 1) % M] + 1); dp[i & 1][m] = len; dpMax[i] = max(dpMax[i], len); } for(int m : master[C[i - 1]]) dp[!(i & 1)][m] = 0; } int ans = 0, pos = -1; for(int i = M - 1, d = 1, flag = 0; i < N && d > 0; i++, d--) { if (dpMax[i] == M) pos = i, flag = 1; if ((d == 1 || i == N - 1) && flag) ans++, d = M - (i - pos) + 1, flag = 0; } if (pos == N - 1) return ans; return -1; }
#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...