Submission #74434

#TimeUsernameProblemLanguageResultExecution timeMemory
74434vexZalmoxis (BOI18_zalmoxis)C++14
100 / 100
185 ms11660 KiB
#include <bits/stdc++.h> #define maxn 1000005 using namespace std; int n,k; int a[maxn]; vector<int>sol; stack<int>s; bool nov[maxn]; void solve() { s.push(a[0]); sol.push_back(a[0]); nov[0]=false; for(int i=1;i<n;i++) { while(!s.empty() && s.top()<a[i]) { sol.push_back(s.top()); nov[sol.size()-1]=true; int tt=s.top()+1;s.pop(); while(!s.empty() && s.top()==tt) { s.pop(); tt++; } s.push(tt); } if(s.top()==a[i]) { sol.push_back(a[i]); nov[sol.size()-1]=false; s.pop(); int tt=a[i]+1; while(!s.empty() && s.top()==tt) { s.pop(); tt++; } s.push(tt); } else{ s.push(a[i]); sol.push_back(a[i]); nov[sol.size()-1]=false; } } while(s.top()!=30) { sol.push_back(s.top()); nov[sol.size()-1]=true; int tt=s.top()+1; s.pop(); while(!s.empty() && s.top()==tt) { s.pop(); tt++; } s.push(tt); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin>>n>>k; for(int i=0;i<n;i++)cin>>a[i]; solve(); //for(auto x:sol)cout<<x<<" "; int sz=sol.size(); k-=(sz-n); int mmm=30; for(int i=0;i<sz;i++) { if(!nov[i] || k==0)cout<<sol[i]<<" "; else if((1<<sol[i])-1 >=k) { while((1<<mmm) > k)mmm--; int ost=k-(1<<mmm)+1; for(int j=0;j<2*ost;j++)cout<<sol[i]-mmm-1<<" "; for(int j=2*ost;j<=k;j++)cout<<sol[i]-mmm<<" "; k=0; } else { for(int j=0;j<(1<<sol[i]);j++)cout<<"0 "; k-=(1<<sol[i]); k++; } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...