Submission #401928

#TimeUsernameProblemLanguageResultExecution timeMemory
401928faresbasbsPainting Walls (APIO20_paint)C++14
0 / 100
2 ms2636 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; vector<int> vals[100001]; int minimumInstructions(int n , int m , int K , vector<int> c , vector<int> A , vector<vector<int>> B){ for(int i = 0 ; i < m ; i += 1){ for(auto j : B[i]){ vals[j].push_back(i); } } vector<pair<int,int>> q,q2; for(int i : vals[c[0]]){ q.push_back({i,1}); } vector<int> all; for(int i = 1 ; i < n ; i += 1){ q2.clear(); for(auto j : q){ if(j.second == m){ continue; } if(*lower_bound(vals[c[i]].begin(),vals[c[i]].end(),(j.first+1)%m) == (j.first+1)%m){ q2.push_back({(j.first+1)%m,j.second+1}); if(j.second == m-1){ all.push_back(i-m+1); } } } for(auto j : vals[c[i]]){ q2.push_back({j,1}); } swap(q,q2); } if(all.size() == 0 || all[0] != 0){ return -1; } int pre = 0 , mx = 0 , cnt = 1; for(int i = 0 ; i < all.size() ; i += 1){ if(pre+m >= all[i]){ mx = all[i]; continue; } if(mx == pre){ return -1; } cnt += 1 , pre = mx; i -= 1; } if(pre+m == n){ return cnt; } pre = mx , cnt += 1; if(pre+m == n){ return cnt; } return -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:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |  for(int i = 0 ; i < all.size() ; i += 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...