Submission #731437

#TimeUsernameProblemLanguageResultExecution timeMemory
731437ogibogi2004Permutation (APIO22_perm)C++17
91.33 / 100
4 ms384 KiB
#include "perm.h" #include<bits/stdc++.h> #define ll long long using namespace std; vector<int> construct_permutation(long long k) { vector<int>ret; ll cur=1; for(int i=0;;i++) { ret.push_back(i); cur*=2; if(cur>k) { ret.pop_back(); cur/=2; break; } } ll diff=k-cur; int cnt=-1; for(ll j=60;j>=0;j--) { if(diff&(1ll<<j)) { //insert new number cnt where there will be j numbers after it vector<int>ret1; reverse(ret.begin(),ret.end()); for(int l=0;l<j;l++)ret1.push_back(ret[l]); ret1.push_back(cnt); for(int l=j;l<ret.size();l++)ret1.push_back(ret[l]); cnt--; ret=ret1; reverse(ret.begin(),ret.end()); } } for(int i=0;i<ret.size();i++) { ret[i]-=cnt+1; } /*for(auto xd:ret)cout<<xd<<" "; cout<<endl;*/ return ret; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |             for(int l=j;l<ret.size();l++)ret1.push_back(ret[l]);
      |                         ~^~~~~~~~~~~
perm.cpp:37:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for(int i=0;i<ret.size();i++)
      |                 ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...