제출 #654043

#제출 시각아이디문제언어결과실행 시간메모리
654043VovamatrixZalmoxis (BOI18_zalmoxis)C++14
100 / 100
166 ms28188 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; #define PI acos(-1) #define LSB(i) ((i) & -(i)) #define ll long long #define pb push_back #define mp make_pair #define mt make_tuple #define fi first #define sc second #define th third #define fo fourth #define pii pair<int,int> #define pll pair<ll,ll> #define ldb double #define MOD 1000000007 #define endl "\n" #define all(data) data.begin(),data.end() #define TYPEMAX(type) std::numeric_limits<type>::max() #define TYPEMIN(type) std::numeric_limits<type>::min() #define ima_li_te(D,d) find(all(D),d) #define MAXN 1000007 ll a[MAXN]; stack<ll> s; vector<pll> v; int main() { ios::sync_with_stdio(false); cin.tie(0); ll n,k; cin>>n>>k; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=n;i++) { ll x=a[i]; while(!s.empty() && s.top()<x) { ll y=s.top(); v.pb(mp(y,1)); k--; while(!s.empty() && s.top()==y) { s.pop(); y++; } s.push(y); } v.pb(mp(x,0)); while(!s.empty() && s.top()==x) { s.pop(); x++; } s.push(x); } while(!s.empty() && s.top()<30) { ll y=s.top(); v.pb(mp(y,1)); k--; while(!s.empty() && s.top()==y) { s.pop(); y++; } s.push(y); } for(auto x:v) { if(x.sc==1) { while(!s.empty()) s.pop(); s.push(x.fi); while(!s.empty() && k>0) { ll y=s.top(); s.pop(); if(y==0) cout<<0<<" "; else { s.push(y-1); s.push(y-1); k--; } } while(!s.empty()) { cout<<s.top()<<" "; s.pop (); } } else cout<<x.fi<<" "; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...