Submission #681156

#TimeUsernameProblemLanguageResultExecution timeMemory
681156QwertyPiPermutation (APIO22_perm)C++17
100 / 100
2 ms340 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; std::vector<int> construct_permutation(long long k){ vector<int> ans; int l = 0, r = 1; int mn0 = -1, mn1 = -1; int b = 59; while(~k & (1LL << b)) b--; for(b--; b >= 0;){ if(b >= 1 && (k >> b - 1) % 2 && (k >> b) % 2 && mn0 != -1 && mn1 != -1){ ans.push_back(r++); ans.push_back(r++); ans[mn0]--; ans[mn1]--; ans.push_back(l + 2); l--; b -= 2; }else{ if((k >> b) % 2){ ans.push_back(r++); mn0 = mn1; mn1 = ans.size(); ans.push_back(l--); }else{ ans.push_back(r++); } b--; } } int mn = *min_element(ans.begin(), ans.end()); for(auto& i : ans) i -= mn; return ans; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:13:24: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   13 |   if(b >= 1 && (k >> b - 1) % 2 && (k >> b) % 2 && mn0 != -1 && mn1 != -1){
      |                      ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...