Submission #1089870

#TimeUsernameProblemLanguageResultExecution timeMemory
1089870lucriZalmoxis (BOI18_zalmoxis)C++17
0 / 100
124 ms262144 KiB
#include <bits/stdc++.h> using namespace std; int n,k,v[1000010]; queue<int>ad[1000010]; vector<pair<int,int>>val[35]; void scrie(int val) { if(val==0||k==0) { cout<<val<<' '; return; } --k; scrie(val-1); scrie(val-1); return; } int main() { cin>>n>>k; for(int i=1;i<=n;++i) { cin>>v[i]; val[v[i]].push_back({i,i}); } for(int va=0;va<=29;++va) { sort(val[va].begin(),val[va].end()); int sz=val[va].size(); for(int i=0;i<sz;++i) { if(i+1==sz||val[va][i].second+1!=val[va][i+1].first) { --k; ad[val[va][i].second].push(va); val[va+1].push_back(val[va][i]); } else { val[va+1].push_back({val[va][i].first,val[va][i+1].second}); ++i; } } val[va].clear(); } if(k<0) return -1; if(val[30].size()!=1) return -1; if(val[30][0].first!=1||val[30][0].second!=n) return -1; for(int i=1;i<=n;++i) { cout<<v[i]<<' '; while(!ad[i].empty()) { scrie(ad[i].front()); ad[i].pop(); } } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...