Submission #918494

#TimeUsernameProblemLanguageResultExecution timeMemory
918494tuannmPermutation (APIO22_perm)C++17
10 / 100
1008 ms712 KiB
#include<bits/stdc++.h> #include "perm.h" #define pb push_back using namespace std; vector<int> construct_permutation(long long k){ vector<int> ans; for(long long N = k; N <= k + 500; ++N){ if(N % 2 != 0) continue; multiset<int> tmp; vector<int> v; for(int i = 1; (1LL << i) <= N; ++i){ if(N & (1LL << i)) tmp.insert(i); } if((int)tmp.size() > N - k + 1) continue; bool ok = true; while((int)tmp.size() < N - k + 1){ auto it = tmp.lower_bound(2); if(it == tmp.end()){ ok = false; break; } tmp.erase(it); int add = *it - 1; tmp.insert(add); tmp.insert(add); } if(!ok) continue; int m = 0; for(auto i : tmp) m += i; for(auto i : tmp){ vector<int> tttt; for(int j = 1; j <= i; ++j) tttt.pb(--m); reverse(tttt.begin(), tttt.end()); for(auto j : tttt) v.pb(j); } if(ans.empty() || (int)ans.size() > (int)v.size()) ans = v; } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...