Submission #873226

#TimeUsernameProblemLanguageResultExecution timeMemory
873226salmonPermutation (APIO22_perm)C++17
10 / 100
1 ms356 KiB
#include "perm.h" #include <bits/stdc++.h> using namespace std; vector<int> construct_permutation(long long k){ if(k <= 90){ vector<int> v; for(int i = 0; i < k - 1; i++){ v.push_back(i); } reverse(v.begin(),v.end()); return v; } vector<int> v; vector<int> temp; vector<int> bits; deque<int> dq; bool flag = false; int cont = 0; int ze = 1; while(k != 0){ bits.push_back(k % 2); k /= 2; } bits.pop_back(); reverse(bits.begin(),bits.end()); if(bits[0] == 1){ flag = true; v.push_back(1); v.push_back(0); if(bits[1] == 0){ temp.clear(); temp.push_back(0); for(int i : v){ temp.push_back(i + 1); } v = temp; } else{ temp.clear(); temp.push_back(1); for(int i : v){ temp.push_back(i + 2); } temp.push_back(0); v = temp; } } else{ flag = false; v.push_back(0); if(bits[1] == 0){ v = vector<int> {0,1}; } else{ v = vector<int> {2,0,1}; } } for(int i = 2; i < bits.size(); i++){ if(flag){ if(bits[i] == 1 && i < bits.size() - 1 && bits[i + 1] == 1){ temp.clear(); temp.push_back(v.size() - 1); temp.push_back(0); temp.push_back(1); for(int i : v){ if(i >= v.size() - 2){ temp.push_back(i + 3); } else temp.push_back(i + 2); } v = temp; i++; } else if(bits[i] == 0){ temp.clear(); temp.push_back(0); for(int i : v){ temp.push_back(i + 1); } v = temp; } else{ temp.clear(); temp.push_back(1); for(int i : v){ temp.push_back(i + 2); } temp.push_back(0); v = temp; } } else{ if(bits[i] == 1 && i < bits.size() - 1 && bits[i + 1] == 1){ for(int i = 0; i < v.size(); i++){ if(v[i] >= 2){ v[i]++; } } v.push_back(v.size() + 1); v.push_back(v.size() + 1); v.push_back(2); i++; } else if(bits[i] == 0){ v.push_back(v.size()); } else{ temp.clear(); temp.push_back(v.size() + 1); for(int i : v){ temp.push_back(i); } temp.push_back(v.size()); v = temp; } } } return v; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:79:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i = 2; i < bits.size(); i++){
      |                    ~~^~~~~~~~~~~~~
perm.cpp:81:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |             if(bits[i] == 1 && i < bits.size() - 1 && bits[i + 1] == 1){
      |                                ~~^~~~~~~~~~~~~~~~~
perm.cpp:89:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   89 |                     if(i >= v.size() - 2){
      |                        ~~^~~~~~~~~~~~~~~
perm.cpp:122:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  122 |             if(bits[i] == 1 && i < bits.size() - 1 && bits[i + 1] == 1){
      |                                ~~^~~~~~~~~~~~~~~~~
perm.cpp:123:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |                 for(int i = 0; i < v.size(); i++){
      |                                ~~^~~~~~~~~~
perm.cpp:25:9: warning: unused variable 'cont' [-Wunused-variable]
   25 |     int cont = 0;
      |         ^~~~
perm.cpp:26:9: warning: unused variable 'ze' [-Wunused-variable]
   26 |     int ze = 1;
      |         ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...