Submission #1277058

#TimeUsernameProblemLanguageResultExecution timeMemory
1277058al95ireyizPermutation (APIO22_perm)C++20
0 / 100
0 ms332 KiB
#pragma GCC optimize("O3", "fast-math", "unroll-loops", "no-stack-protector") #include <bits/stdc++.h> using namespace std; #if !defined(ONLINE_JUDGE) and !defined(EVAL) #include "template/debug.h" #else #define d(x...) #endif #define fr first #define er erase #define in insert #define sc second #define ll long long #define pb push_back #define vll vector<ll> #define pll pair<ll,ll> #define len(x) (ll) x.size() #define all(x) x.begin(),x.end() const ll INF = 1e9, INFL = 1e18; const ll MOD = 1e9 + 7; // const ll MOD = 998244353; const ll maxn = 2e5 + 5; ll n, m, k = 0; ll f(ll ind, vector<int> &v){ // [0, ind - 1] kohne yol // [ind, n - 1] yeni yol ll cv = 0; for(ll i = 0; i <= ind - 1; i ++){ cv += v[i]; } for(ll i = ind; i <= n - 1; i ++){ if(i == ind) cv += v[i]; else cv += v[i] - (v[ind] - 1); } return cv; } std::vector<int> construct_permutation(long long _k) { m = _k; vector<int> v, cv; ll cm = 0, noilk = 0; while(m){ ll l = 1, r = 60, cv; while(l <= r){ ll md = (l + r) >> 1; if((1LL << md) - noilk <= m){ cv = md, l = md + 1; } else{ r = md - 1; } } v.pb(cv); m -= (1LL << cv) - noilk; if(noilk == 0) noilk = 1; cm += cv; } n = len(v); sort(all(v)); ll mn = INF, ind = 0; for(ll i = 0; i < len(v); i ++){ ll x = f(i, v); if(x < mn){ mn = x; ind = i; } } for(ll i = 0; i <= ind - 1; i ++){ for(ll j = cm - v[i] + 1; j <= cm; j ++){ // cout << j << ' '; cv.pb(j - 1); } cm -= v[i]; } for(ll i = ind + 1; i <= n - 1; i ++){ v[i] -= v[ind] - 1; } for(ll i = 1; i <= v[ind]; i ++){ cv.pb(i - 1); } for(ll i = ind + 1; i <= n - 1; i ++){ for(ll j = cm - v[i] + 1; j <= cm; j ++){ cv.pb(j - 1); } cm -= v[i]; } return cv; } // void _() { // ll q; // cin >> q; // auto v = construct_permutation(q); // for(auto i : v) cout << i << ' ' ; // } // signed main() { // ll tm = clock(); // cin.tie(0)->sync_with_stdio(0); // ll t = 1; // // cin >> t; // for(ll tt = 1; tt <= t; tt ++) _(); // cerr << "\n\033[1;31mTime: \033[1;30m" \ // << (double)(clock()-tm)/1000000 << "\033[1;32m seconds\n"; // }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...