Submission #401943

#TimeUsernameProblemLanguageResultExecution timeMemory
401943faresbasbsPainting Walls (APIO20_paint)C++14
63 / 100
1579 ms14460 KiB
#include <bits/stdc++.h> #include "paint.h" using namespace std; int v1[100001],v2[100001]; 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){ v1[i] = v2[i] = -1000000000; for(auto j : B[i]){ vals[j].push_back(i); } } vector<int> q1,q2; for(int i : vals[c[n-1]]){ q1.push_back(i); v1[i] = n-1; } vector<int> all; bool ok = 0; for(auto j : q1){ if(v1[j]-(n-1) >= m-1){ ok = 1; } } if(ok){ all.push_back(n-1); } for(int i = n-2 ; i >= 0 ; i -= 1){ for(auto j : vals[c[i]]){ if(vals[c[i+1]].size() && vals[c[i+1]].back() >= (j+1)%m && *lower_bound(vals[c[i+1]].begin(),vals[c[i+1]].end(),(j+1)%m) == (j+1)%m){ q2.push_back(j); v2[j] = v1[(j+1)%m]; }else{ q2.push_back(j); v2[j] = i; } } for(auto j : q1){ v1[j] = -1000000000; } for(auto j : q2){ v1[j] = v2[j]; v2[j] = -1000000000; } swap(q1,q2); bool ok = 0; for(auto j : q1){ if(v1[j]-i >= m-1){ ok = 1; } } if(ok){ all.push_back(i); } q2.clear(); } reverse(all.begin(),all.end()); 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:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |  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...