Submission #722141

#TimeUsernameProblemLanguageResultExecution timeMemory
722141yeysoPermutation (APIO22_perm)C++17
10 / 100
6 ms596 KiB
#include <bits/stdc++.h> using namespace std; #include "perm.h" #define ll long long; vector<int> construct_permutation(long long k) { k -= 1; long long x = 1; vector<long long> sub = {0}; vector<int> res; while(sub[sub.size()-1] < k * 2){ sub.push_back(pow(2, x)-1); x += 1; } while(k > 0){ for(int i = 0; i < sub.size(); i ++){ if(sub[i] > k){ k -= sub[i-1]; res.push_back(i-1); break; } } } vector<vector<int>> inc; int res0 = 0; for(int i = 0; i < res.size(); i ++){ inc.push_back({}); for(int j = 0; j < res[i]; j ++){ inc[i].push_back(j+res0); } res0 += res[i]; } vector<int> res2 = {}; reverse(inc.begin(), inc.end()); for(long long i = 0; i < inc.size(); i ++){ for(long long j = 0; j < inc[i].size(); j ++){ res2.push_back(inc[i][j]); } } return res2; }

Compilation message (stderr)

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