제출 #1225871

#제출 시각아이디문제언어결과실행 시간메모리
1225871KALARRY벽 칠하기 (APIO20_paint)C++20
28 / 100
1599 ms165012 KiB
//chockolateman #include<bits/stdc++.h> using namespace std; int n,m,dp[100005],c[100005]; map<int,bool> likes[100005]; bool test_end(int i) { int y = i - m + 1; if(y <= 0) return false; for(int x = 0 ; x < m ; x++) { bool problem = false; for(int l = 0 ; l < m ; l++) { int cur_x = (x+l)%m; int cur_y = y+l; if(!likes[cur_x][c[cur_y]]) { problem = true; break; } } if(!problem) return true; } return false; } 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; for(int i = N ; i >= 1 ; i--) //make it 1-indexed c[i] = C[i-1]; for(int j = 0 ; j < M ; j++) for(auto x : B[j]) likes[j][x] = true; dp[0] = 0; for(int i = 1 ; i <= N ; i++) { dp[i] = -1; if(!test_end(i)) continue; for(int k = i-1 ; k >= i-M ; k--) { if(dp[k] != -1) { if(dp[i]==-1) dp[i] = dp[k] + 1; else dp[i] = min(dp[i],dp[k] + 1); } } } return dp[N]; }
#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...