Submission #605435

#TimeUsernameProblemLanguageResultExecution timeMemory
605435AugustinasJucasPermutation (APIO22_perm)C++17
10 / 100
1078 ms1348 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; vector<int> construct_permutation(long long k) { vector<int> RET(3000, 0); long long K = k; for(int H = 0; H < k-1; H++){ k = K - H; 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 + H; for(int i = 0; i < H; i++) { ret.push_back(ind--); } for(int i = 0; i < init.size(); i++) { if((1ll << i) & liko) { ret.push_back(ind); ind--; } ret.push_back(init[i]); } if(ret.size() < RET.size()) { RET = ret; } // 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:29:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for(int i = 0; i < init.size(); i++) {
      |                        ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...