제출 #703519

#제출 시각아이디문제언어결과실행 시간메모리
703519khanhhdz191순열 (APIO22_perm)C++17
100 / 100
6 ms360 KiB
#include <bits/stdc++.h> #include <perm.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 const ll inf=2e18; ll C(vector<int> v) { ll m=(int)v.size(); vector<ll> f(m); ll sum=1; for (int i=0; i<m; i++) { f[i]=1; for (int j=0; j<i; j++) { if (v[j]<v[i]) f[i]+=f[j]; f[i]=min(f[i],inf); } sum+=f[i]; sum=min(sum,inf); } return sum; } vector<int> 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}; auto ans=construct_permutation(k/4); int n=(int)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(n+1); ans.pb(-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 (int 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...