Submission #558697

#TimeUsernameProblemLanguageResultExecution timeMemory
558697Ai7081Painting Walls (APIO20_paint)C++17
63 / 100
1582 ms14248 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; const bool debug = 0; const int inf = 1e9; int minimumInstructions(int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { vector<int> col[K+5]; for (int i=0; i<B.size(); i++) for (auto it : B[i]) col[it].push_back(i); vector<int> dp(N+5, inf); vector<int> cnt(M+5, 0); deque<pair<int, int>> dq; int n_good = 0; for (int i=0; i<N; i++) { if (i >= M) { for (auto j : col[C[i-M]]) n_good -= (cnt[(M+(j-(i-M))%M)%M]-- == M); } for (auto j : col[C[i]]) n_good += (++cnt[(M+(j-i)%M)%M] == M); if (n_good) { if (i == M-1) dp[i] = 1; else { while (!dq.empty() && dq.front().second < i-M) dq.pop_front(); if (!dq.empty()) dp[i] = dq.front().first + 1; } while (!dq.empty() && dq.back().first >= dp[i]) dq.pop_back(); dq.push_back({dp[i], i}); } } if (debug) { printf("dp : "); for (int i=0; i<N; i++) printf("%d ", dp[i]); printf("\n"); } return (dp[N-1] < inf ? dp[N-1] : -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:11:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for (int i=0; i<B.size(); i++) for (auto it : B[i]) col[it].push_back(i);
      |                   ~^~~~~~~~~
#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...