Submission #985490

#TimeUsernameProblemLanguageResultExecution timeMemory
985490GhettoPermutation (APIO22_perm)C++17
91.33 / 100
8 ms440 KiB
#include "perm.h" #include <bits/stdc++.h> using lint = long long; using namespace std; vector<int> normalise(vector<int> x, int n_pos) { int diff = x.size() - n_pos - 1; for (int& y : x) y += diff; return x; } vector<int> construct_permutation(lint k) { int max_bit = 0; for (int i = 0; i <= 60; i++) if (k & (lint) powl(2, i)) max_bit = i; assert(max_bit != 0); vector<int> ans; for (int i = 1; i <= max_bit; i++) ans.push_back(i); int prev = 1; for (int bit = 60; bit >= 0; bit--) { if (!(k & (lint) powl(2, bit))) continue; if (bit == max_bit) continue; prev--; int diff = max_bit - bit; for (auto it = ans.begin(); it != ans.end(); it++) { if (*it != diff) continue; ans.insert(next(it, 1), prev); break; } } // for (int x : ans) cout << x << " "; // cout << endl; ans = normalise(ans, max_bit); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...