Submission #558701

#TimeUsernameProblemLanguageResultExecution timeMemory
558701Ai7081Painting Walls (APIO20_paint)C++17
100 / 100
1095 ms14924 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; 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[(N+j-i)%M]-- == M); } for (auto j : col[C[i]]) n_good += (++cnt[(N+j-i)%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}); } } 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:10:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     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...