Submission #605423

#TimeUsernameProblemLanguageResultExecution timeMemory
605423AugustinasJucasPermutation (APIO22_perm)C++17
91.33 / 100
2 ms384 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; vector<int> construct_permutation(long long k) { vector<int> init; int ind = 0; long long liko = 0; for(int i = 0; i < 64; i++) { long long bus = (1ll << i); if(bus > k) { // desim i-1 tu. for(int j = 0; j < i-1; j++) init.push_back(ind++); liko = k - (1ll << (i-1)); break; } } // cout << "liko = " << liko << ", popcnt = " << __builtin_popcount(liko) << endl; vector<int> ret; ind += __builtin_popcountll(liko) - 1; for(int i = 0; i < init.size(); i++) { if((1ll << i) & liko) { ret.push_back(ind); ind--; } ret.push_back(init[i]); } // cout << "ret = "; for(auto x : ret) cout << x << " "; //cout << endl; return ret; }

Compilation message (stderr)

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