Submission #963147

#TimeUsernameProblemLanguageResultExecution timeMemory
963147kilkuwuPermutation (APIO22_perm)C++17
100 / 100
2 ms504 KiB
#include "perm.h" #include <bits/stdc++.h> std::vector<int> construct_permutation(long long k) { if (k < 4) { if (k == 1) return {}; if (k == 2) return {0}; return {1, 0}; } auto v = construct_permutation(k / 4); int r = k % 4; if (r == 0) { v.push_back(v.size()); v.push_back(v.size()); return v; } if (r == 1) { v.push_back(v.size()); v.push_back(v.size()); v.insert(v.begin(), v.size()); return v; } if (r == 2) { // adding two into our thing v.push_back(v.size()); v.push_back(v.size()); v.insert(v.begin() + 1, v.size()); return v; } int p0 = std::find(v.begin(), v.end(), 0) - v.begin(); int p1 = std::find(v.begin(), v.end(), 1) - v.begin(); if (p1 < p0) { v.push_back(v.size()); v.push_back(v.size()); for (int& i : v) { if (i >= 2) { i++; } } v.push_back(2); return v; } // p1 > p0 v.push_back(v.size()); v.push_back(v.size()); for (int& i : v) { if (i >= 1) i++; } v.push_back(1); for (int& i : v) { i++; } v.push_back(0); return v; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...