Submission #737714

#TimeUsernameProblemLanguageResultExecution timeMemory
737714Abrar_Al_SamitPainting Walls (APIO20_paint)C++17
63 / 100
1596 ms409432 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; const int nax = 1e5 + 1; vector<int> col_to_wall[nax], cand[nax]; bool good[nax]; int dp[2][1000]; int minimumInstructions( int N, int M, int K, vector<int> C, vector<int> A, vector<vector<int>> B) { for(int i=0; i<N; ++i) { col_to_wall[C[i]].push_back(i); } for(int i=0; i<M; ++i) { for(int j=0; j<A[i]; ++j) { for(int x : col_to_wall[B[i][j]]) { cand[x].push_back(i); } } } for(int i=0; i<K; ++i) { col_to_wall[i].clear(); } int rw = 0; for(int i=N-1; i>=1; --i, rw = 1-rw) { int ptr = 0; for(int j=0; j<cand[i-1].size(); ++j) { dp[rw][j] = 0; if(cand[i-1][j]+1==M) { if(!cand[i].empty() && cand[i][0]==0) { dp[rw][j] = 1 + dp[1-rw][0]; } continue; } while(ptr+1<cand[i].size() && cand[i][ptr+1]<=cand[i-1][j]+1) { ++ptr; } if(!cand[i].empty() && cand[i][ptr]==cand[i-1][j]+1) { dp[rw][j] = 1 + dp[1-rw][ptr]; } } if(i-1<=N-M) { for(int j=0; j<cand[i-1].size(); ++j) { int cur = 1 + dp[rw][j]; if(cur>=M) good[i-1] = 1; } } } if(M==1 && !cand[N-1].empty()) good[N-1] = 1; if(!good[0]) return -1; int last = 0, pending = -1; int ans = 1; for(int i=1; i<N; ++i) { if(good[i]) { pending = i; } if(last+M==i) { if(pending==-1) return -1; last = pending; pending = -1; ++ans; } } return ans; }

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:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |         for(int j=0; j<cand[i-1].size(); ++j) {
      |                      ~^~~~~~~~~~~~~~~~~
paint.cpp:46:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |             while(ptr+1<cand[i].size() && cand[i][ptr+1]<=cand[i-1][j]+1) {
      |                   ~~~~~^~~~~~~~~~~~~~~
paint.cpp:55:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |             for(int j=0; j<cand[i-1].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...