Submission #347980

#TimeUsernameProblemLanguageResultExecution timeMemory
347980arnold518Painting Walls (APIO20_paint)C++14
51 / 100
145 ms160492 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 2e4; const int MAXM = 2000; const int MAXK = 1e5; int N, M, K; int C[MAXN+10]; vector<int> B[MAXK+10]; int dp[MAXN+10][MAXM+10], chk[MAXN+10]; int dp2[MAXN+10]; int minimumInstructions(int _N, int _M, int _K, vector<int> _C, vector<int> _A, vector<vector<int>> _B) { N=_N; M=_M; K=_K; for(int i=0; i<N; i++) C[i]=_C[i]; for(int i=0; i<M; i++) { for(auto it : _B[i]) { B[it].push_back(i); } } for(int i=0; i<N; i++) { for(auto it : B[C[i]]) { dp[i][it]=1; if(i!=0 && dp[i-1][(it+M-1)%M]) { dp[i][it]=dp[i-1][(it+M-1)%M]+1; } if(dp[i][it]>=M) { chk[i+1]=1; } } } /* for(int i=0; i<M; i++) { for(int j=0; j<N; j++) { printf("%d ", dp[j][i]); } printf("\n"); } */ for(int i=1; i<=N; i++) { dp2[i]=987654321; if(!chk[i]) continue; for(int j=max(i-M, 0); j<i; j++) { dp2[i]=min(dp2[i], dp2[j]+1); } } /* deque<int> DQ; DQ.push_back(0); for(int i=1; i<=N; i++) { dp2[i]=987654321; while(!DQ.empty() && DQ.front()<i-M) DQ.pop_front(); if(chk[i] && !DQ.empty()) { dp2[i]=dp2[DQ.front()]+1; } while(!DQ.empty() && dp2[DQ.back()]>=dp2[i]) DQ.pop_back(); DQ.push_back(i); //printf("%d ", dp2[i]); } */ if(dp2[N]==987654321) return -1; return dp2[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...