제출 #1035255

#제출 시각아이디문제언어결과실행 시간메모리
1035255amine_aroua순열 (APIO22_perm)C++17
69.72 / 100
15 ms1116 KiB
#include "perm.h" #include<bits/stdc++.h> using namespace std; #define ll long long std::vector<int> construct_permutation(long long k) { int sz = 10000; vector<int> best; for(ll l = 1 ;l < 61 ;l++) { ll x = k + l - 1; if(__builtin_popcountll(x) <= l) { int n = 0; vector<int> bits; for(ll i = 0 ; i < 61 ; i++) { if((1ll<<i) & x) { bits.push_back(i); } } bool ok = 1; while ((int)bits.size() < l) { bool acc = 0; for(int i = 0 ; (int)bits.size()< l && i < (int)bits.size() ; i++) { int bit = bits[i]; if(bit >= 1) { acc = 1; bits[i] = --bit; bits.push_back(bits[i]); } } if(!acc) { ok = 0; break; } } if(!ok) continue; for(auto bit : bits) n+=bit; n--; vector<int> perm; for(auto i : bits) { for(int j = n - i + 1 ; j <= n ; j++) { perm.push_back(j); } n-=i; } if((int)perm.size() < sz) { sz = (int)perm.size(); best = perm; } } } return best; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...