Submission #954211

#TimeUsernameProblemLanguageResultExecution timeMemory
954211vjudge1Painting Walls (APIO20_paint)C++17
100 / 100
349 ms14516 KiB
#include "paint.h" #include<bits/stdc++.h> using namespace std; const int maxn=100000+10; int n,m,k; vector<int>allk[maxn]; int len[maxn],last[maxn],fakelast[maxn],fakelen[maxn]; int minimumInstructions(int N, int M, int K, std::vector<int> C, std::vector<int> A, std::vector<std::vector<int>> B) { n=N; m=M; k=K; for(int i=0;i<m;i++){ for(auto x:B[i]){ allk[x].push_back(i); } } vector<int>res(n+2); for(int i=0;i<maxn;i++){ last[i]=n; } for(int i=n-1;i>=0;i--){ for(auto x:allk[C[i]]){ fakelast[x]=i; if(last[(x+1)%m]!=i+1){ fakelen[x]=1; }else{ fakelen[x]=min(m,len[(x+1)%m]+1); } } for(auto x:allk[C[i]]){ last[x]=fakelast[x]; len[x]=fakelen[x]; if(len[x]==m){ res[i]=1; } } } // for(int i=0;i<n;i++){ // cout<<i<<" "<<res[i]<<"\n"; // } int ted=0; if(res[0]==0){ return -1; } int mx=-1,fakemx=-1; while(mx!=n-1){ // cout<<mx<<" "<<fakemx<<endl; ted++; fakemx=max(fakemx,res[mx+1]*m+mx); if(fakemx==mx){ return -1; } int j=mx; mx=fakemx; for(;j<=mx;j++){ fakemx=max(fakemx,res[j+1]*m+j); } } return ted; }
#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...