제출 #1132851

#제출 시각아이디문제언어결과실행 시간메모리
1132851GrayZalmoxis (BOI18_zalmoxis)C++20
100 / 100
125 ms15328 KiB
#include <bits/stdc++.h> #include <cassert> #include <iomanip> #include <tuple> #include <vector> using namespace std; #define ll int #define ull unsigned long long #define ld long double #define ff first #define ss second #define ln "\n" #define mp make_pair #define INF 2e18 #define MOD 1e9+7 void get(ll x, ll &i, vector<ll> &a, vector<ll> &res, set<ll> &spec){ if (i<(ll)a.size() and a[i]==x){ res.push_back(a[i]); i++; return; }else if (i<(ll)a.size() and a[i]<x){ get(x-1, i, a, res, spec); get(x-1, i, a, res, spec); }else if (i==(ll)a.size() or a[i]>x){ res.push_back(x); spec.insert(res.size()-1); } } void print(ll x, ll &k){ if (x==0 or k==1){ cout << x << " "; k--; }else if (k){ k--; print(x-1, k); k++; print(x-1, k); } } void solve(){ ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i=0; i<n; i++) cin >> a[i]; vector<ll> res; ll point=0; set<ll> spec; get(30, point, a, res, spec); for (ll i=0; i<(ll)res.size(); i++){ if (spec.count(i)){ spec.erase(i); k-=spec.size(); print(res[i], k); k+=spec.size(); }else{ cout << res[i] << " "; } } } int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); auto start = chrono::high_resolution_clock::now(); ll t=1; // cin >> t; while (t--) solve(); #ifdef LOCAL auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start); cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl; #endif }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...