Submission #702140

#TimeUsernameProblemLanguageResultExecution timeMemory
702140ld_minh4354Permutation (APIO22_perm)C++17
10 / 100
2 ms1876 KiB
#include "perm.h" using namespace std; vector<int> construct_permutation(long long k) { int a[200005],i,j,cur_val,pos,cur_k,n; cur_k=k; n=1;a[1]=0;cur_val=2; while (cur_val*2<=k) { n++;a[n]=n-1; cur_val*=2; } cur_k -= cur_val; while (cur_k > 0) { cur_val=1;pos=1; while (cur_val*2 <= cur_k) { pos++;cur_val*=2; } for (i=n+1;i>pos;i--) a[i]=a[i-1]; n++;a[pos]=n-1; cur_k -= cur_val; } vector<int> ans; for (i=1;i<n+1;i++) ans.push_back(a[i]); return ans; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:6:18: warning: unused variable 'j' [-Wunused-variable]
    6 |  int a[200005],i,j,cur_val,pos,cur_k,n;
      |                  ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...