Submission #347984

#TimeUsernameProblemLanguageResultExecution timeMemory
347984arnold518Painting Walls (APIO20_paint)C++14
0 / 100
3 ms2668 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 = 1e5; const int MAXM = 5e4; const int MAXK = 1e5; int N, M, K; int C[MAXN+10]; vector<int> B[MAXK+10]; int dp[2][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&1][it]=1; if(i!=0 && dp[i-1&1][(it+M-1)%M]) { dp[i&1][it]=dp[i-1&1][(it+M-1)%M]+1; } if(dp[i&1][it]>=M) { chk[i+1]=1; } } } deque<int> DQ; DQ.push_back(0); for(int i=1; i<=N; i++) { dp2[i]=987654321; if(!chk[i]) continue; while(!DQ.empty() && DQ.front()<i-M) DQ.pop_front(); if(DQ.empty()) continue; 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]; }

Compilation message (stderr)

paint.cpp: In function 'int minimumInstructions(int, int, int, std::vector<int>, std::vector<int>, std::vector<std::vector<int> >)':
paint.cpp:37:19: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   37 |    if(i!=0 && dp[i-1&1][(it+M-1)%M])
      |                  ~^~
paint.cpp:39:21: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   39 |     dp[i&1][it]=dp[i-1&1][(it+M-1)%M]+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...