Submission #703510

#TimeUsernameProblemLanguageResultExecution timeMemory
703510khanhhdz191Permutation (APIO22_perm)C++17
0 / 100
1 ms212 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll,ll> #define ff first #define ss second #define pb push_back #define endl "\n" /// ko dc giai nhat chat me tay di /// khanhdzvcl ll C(vector<ll> v) { ll m=(ll)v.size(); vector<ll> f(m); ll sum=1; for (ll i=0; i<m; i++) { f[i]=1; for (ll j=0; j<i; j++) { if (v[j]<v[i]) f[i]+=f[j]; f[i]=min(f[i],(ll)2e18); } sum+=f[i]; sum=min(sum,(ll)2e18); } return sum; } vector<ll> construct_permutation(ll k) { if (k==1) return {}; if (k==2) return {0}; if (k==3) return {1,0}; if (k==4) return {0,1}; vector<ll> ans=construct_permutation(k/4); ll n=(ll)ans.size(); if (k%4==0) { ans.pb(n); // ans.pb(0); ans.pb(n+1); // for (auto &p:ans) p++; return ans; } if (k%4==1) { ans.pb(n); ans.pb(-1); ans.pb(n+1); for (auto &p:ans) p++; return ans; } if (k%4==2) { ans.pb(n); ans.pb(-1); ans.pb(n+1); for (auto &p:ans) p++; return ans; } auto man=ans; ans.pb(n); ans.pb(n+1); for (ll i=0; i<(ll)ans.size(); i++) { if (ans[i]>1) ans[i]++; } ans.pb(2); if (C(ans)==k) return ans; for (auto &p:man) p+=2; man.pb(n+2); man.pb(1); man.pb(n+3); man.pb(0); return man; } /* void tc() { ll k; cin>> k; auto v=construct_permutation(k); for (auto &p:v) cout<< p<<' '; } int main() { // freopen("bi.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_with_stdio(0); cin.tie(nullptr); ll t=1; cin>> t; while (t--) { tc(); cout<< endl; } } */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...