Submission #934344

#TimeUsernameProblemLanguageResultExecution timeMemory
934344irmuunPainting Walls (APIO20_paint)C++17
12 / 100
49 ms13904 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define ff first #define ss second #define all(s) s.begin(),s.end() #define rall(s) s.rbegin(),s.rend() int minimumInstructions(int n,int m,int k,vector<int>C,vector<int>A,vector<vector<int>>B){ vector<int>cnt(k,0); vector<int>pos[k]; int mx=0; for(int i=0;i<m;i++){ for(auto x:B[i]){ cnt[x]++; mx=max(mx,cnt[x]); pos[x].pb(i); } } if(mx<=1){ vector<int>can(k,-1); for(int i=0;i<m;i++){ for(int j=0;j<A[i];j++){ can[B[i][j]]=i; } } for(int i=0;i<n;i++){ if(can[C[i]]==-1) return -1; } vector<int>count(n,0); int cur=1; count[n-1]=1; for(int i=n-2;i>=0;i--){ if(can[C[i]]==can[C[i+1]]-1||(can[C[i+1]]==0&&can[C[i]]==m-1)){ cur++; } else{ cur=1; } count[i]=cur; } int ans=0; bool ok=true; if(count[0]<m) return -1; ans++; int r=m-1,nxt=0; for(int i=1;i<n;i++){ if(count[i]>=m){ nxt=i; } if(i>r){ r=nxt+m-1; if(i>r) return -1; ans++; } } return ans; } vector<int>q(m),q1(m,-1e9); vector<int>L(n,-1e9); vector<int>change,back; for(int j=0;j<m;j++){ for(auto j:pos[C[j]]){ q[j]=1; L[n-1]=1; change.pb(j); } } for(int i=n-2;i>=0;i--){ back=change; for(auto j:change){ q1[j]=q[j]; } change.clear(); for(auto j:pos[C[i]]){ if(i==n-1||q1[(j+1)%m]==-1e9){ q[j]=1; change.pb(j); } else{ q[j]=q1[(j+1)%m]+1; change.pb(j); } L[i]=max(L[i],q[j]); } for(auto j:back){ q1[j]=-1e9; } } vector<int>mn(n+1,1e9); mn[n]=0; multiset<int>st; for(int i=n-m+1;i<=n;i++){ st.insert(mn[i]); } for(int i=n-m;i>=0;i--){ bool ok=(L[i]>=m); if(ok){ mn[i]=*st.begin()+1; } st.erase(st.find(mn[i+m])); st.insert(mn[i]); } if(mn[0]>=1e9) return -1; return mn[0]; }

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:46:14: warning: unused variable 'ok' [-Wunused-variable]
   46 |         bool ok=true;
      |              ^~
#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...