Submission #74428

#TimeUsernameProblemLanguageResultExecution timeMemory
74428vexZalmoxis (BOI18_zalmoxis)C++14
45 / 100
211 ms11548 KiB
#include <bits/stdc++.h> #define maxn 1000005 using namespace std; int n,k; int a[maxn]; vector<int>sol; stack<int>s; bool bio[maxn]={true}; void solve() { s.push(a[0]); sol.push_back(a[0]); for(int i=1;i<n;i++) { while(!s.empty() && s.top()<a[i]) { sol.push_back(s.top()); bio[sol.size()-1]=false; 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]); 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]); } } while(s.top()!=30) { sol.push_back(s.top()); bio[sol.size()-1]=false; 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(bio[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...