Submission #289406

#TimeUsernameProblemLanguageResultExecution timeMemory
289406beso123Painting Walls (APIO20_paint)C++14
100 / 100
1375 ms13628 KiB
#include "paint.h" #include <bits/stdc++.h> using namespace std; int minimumInstructions(int n,int m,int s,vector<int> col,vector<int> Size,vector<vector<int>> b){ vector<int> mp[s+1]; for(int k=0;k<m;k++){ for(int i=0;i<Size[k];i++){ mp[b[k][i]].push_back(k); } } deque<int> v; v.resize(m,0); for(int k=0;k<m;k++){ for(int i=0;i<mp[col[k]].size();i++){ int nom=mp[col[k]][i]; nom=((nom-k)+m)%m; v[nom]++; } } vector<int> a(n,0); for(int k=0;k<v.size();k++) if(v[k]==m) a[m-1]=1; for(int k=m;k<n;k++){ int cl=col[k-m]; for(int i=0;i<mp[cl].size();i++){ v[mp[cl][i]]--; } cl=col[k]; int x=v[v.size()-1]; v.pop_back(); v.push_front(x); for(int i=0;i<mp[cl].size();i++){ v[(mp[cl][i]+1)%m]++; if(v[(mp[cl][i]+1)%m]==m) a[k]=1; } } int ans=0; vector<int> w(n+1,-1); if(a[m-1]==1) w[m-1]=m-1; else return -1; for(int k=m;k<n;k++){ w[k]=w[k-1]; if(a[k]==1) w[k]=k; } int j=m-1; while(true){ ans++; if(j==n-1) break; int i=(j+m); if(i>=n) i=n-1; if(w[i]==w[j]) return -1; j=w[i]; } 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:14:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   14 |         for(int i=0;i<mp[col[k]].size();i++){
      |                     ~^~~~~~~~~~~~~~~~~~
paint.cpp:21:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for(int k=0;k<v.size();k++)
      |                 ~^~~~~~~~~
paint.cpp:26:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for(int i=0;i<mp[cl].size();i++){
      |                     ~^~~~~~~~~~~~~~
paint.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         for(int i=0;i<mp[cl].size();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...