Submission #993592

#TimeUsernameProblemLanguageResultExecution timeMemory
993592abczzPermutation (APIO22_perm)C++17
0 / 100
1 ms604 KiB
#include "perm.h" #include <iostream> #define ll long long using namespace std; vector <int> base2(ll k) { vector <int> V; ll mxbit = 0, cnt = 0; for (int i=59; i>=0; --i) { if (k & (1LL<<i)) { mxbit = i; break; } } for (int j=0; j<mxbit; ++j) { if (k & (1LL<<j)) V.push_back(-1); V.push_back(++cnt); } ll x = V.size(); for (auto &u : V) { if (u == -1) u = x--; --u; } return V; } vector <int> base3(ll k) { vector <int> V, U; ll cnt = 0; ll tmp = k/3; while (tmp) { U.push_back(tmp % 3); tmp /= 3; } for (int i=0; i<U.size(); ++i) { if (U[i] == 1) V.push_back(-1); V.push_back(cnt+2); if (U[i] == 2) V.push_back(-1); V.push_back(cnt+1); cnt += 2; } if (U.back() == 2) V.push_back(++cnt); ll x = V.size(); for (auto &u : V) { if (u == -1) u = x--; --u; } return V; } std::vector<int> construct_permutation(long long k) { auto b2 = base2(k); auto b3 = base3(k); if (b2.size() < b3.size()) return b2; else return b3; }

Compilation message (stderr)

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