Submission #972161

#TimeUsernameProblemLanguageResultExecution timeMemory
972161tamir1Permutation (APIO22_perm)C++17
91.33 / 100
2 ms500 KiB
#include "perm.h" #include <iostream> #define ll long long using namespace std; vector<int> construct_permutation(long long k) { ll t=1,i,j,idx,idx1,cnt[200],sum=0; vector<ll> v,u; while(true){ if(t>k) break; v.push_back(t); t=t*2; } fill(cnt,cnt+200,0); while(k>0){ for(i=v.size()-1;i>=0;i--){ if(v[i]<=k){ u.push_back(i); k-=v[i]; break; } } } sum=u[0]; idx1=0; for(i=1;i<u.size();i++){ sum++; cnt[u[i]]++; } idx=sum; vector<int> ans(sum); for(i=ans.size()-1;i>=0;i--){ if(cnt[sum-idx]>0){ ans[i]=idx1; idx1++; cnt[sum-idx]--; } else{ idx--; ans[i]=idx; } } return ans; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:26:11: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |  for(i=1;i<u.size();i++){
      |          ~^~~~~~~~~
perm.cpp:7:11: warning: unused variable 'j' [-Wunused-variable]
    7 |  ll t=1,i,j,idx,idx1,cnt[200],sum=0;
      |           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...