Submission #546270

#TimeUsernameProblemLanguageResultExecution timeMemory
546270cig32Painting Walls (APIO20_paint)C++17
63 / 100
1577 ms13220 KiB
#include "paint.h" #include <iostream> #include <algorithm> #include <utility> #include <unordered_map> #include <map> #include <deque> using namespace std; int minimumInstructions(int N, int M, int K, std::vector<int> C,std::vector<int> A, std::vector<std::vector<int>> B) { int dp[N]; for(int i=0; i<N; i++) dp[i] = 1e9; vector<int> contains[K]; // size of contains[i] = f(i) for(int i=0; i<M; i++) { for(int j=0; j<B[i].size(); j++) { contains[B[i][j]].push_back(i); } } unordered_map<int, int> val[2]; // val[i][j] := maximum chain if i choose contractor j at position i int mxchain[N]; for(int i=0; i<N; i++) { mxchain[i] = -1e9; } for(int i=N-1; i>=0; i--) { for(int j: contains[C[i]]) { val[i & 1][j] = max(val[i & 1][j], val[(i+1) & 1][(j+1) % M] + 1); mxchain[i] = max(mxchain[i], val[i & 1][j]); } val[(i+1) & 1].clear(); } deque<int> mono; for(int i=M-1; i<N; i++) { while(mono.size() && mono[0] < i-M) { mono.pop_front(); } if(mxchain[i-M+1] >= M) { dp[i] = (mono.empty() ? 0 : dp[mono[0]]) + 1; } while(mono.size() && dp[mono[mono.size() - 1]] >= dp[i]) { mono.pop_back(); } mono.push_back(i); } return (dp[N-1] > 1e8 ? -1 : dp[N-1]); }

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:14:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |     for(int j=0; j<B[i].size(); j++) {
      |                  ~^~~~~~~~~~~~
#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...