Submission #718576

#TimeUsernameProblemLanguageResultExecution timeMemory
718576lamPermutation (APIO22_perm)C++17
100 / 100
2 ms340 KiB
#include "perm.h" #include <bits/stdc++.h> #define ll long long using namespace std; void add(vector <int> &ans, vector <int> tmp) { vector <int> tmp2; for (int i:tmp) if (i>0) tmp2.push_back(i); sort(tmp2.begin(),tmp2.end()); for (int i:tmp2) for (int &j:ans) if (j>=i) j++; int bound = ans.size() + tmp.size(); for (int i:tmp) if (i<=0) ans.push_back(bound+i); else ans.push_back(i); } vector<int> construct_permutation(long long k) { vector <int> res; if (k==1) return res; if (k==2) return vector <int>({0}); if (k==3) return vector <int>({1,0}); vector <int> digits; while (k>0) { digits.push_back(int(k&1)); k>>=1; } reverse(digits.begin(),digits.end()); int it=1; if (digits[1]==0) { if (digits[2]==0) res=vector<int>({3,2,1}); else res=vector <int>({2,3,1}); it+=2; } else { res=vector<int>({2,1}); it++; } while (it+1<digits.size()) if (digits[it]==0) { add(res,{0}); it++; } else { if (digits[it+1]==0) add(res,{-1,1,0}); else add(res,{-1,0,3}); it+=2; } if (it<digits.size()) { if (digits[it]==0) add(res,{0}); else add(res,{0,1}); } for (int &i:res) i--; return res; }

Compilation message (stderr)

perm.cpp: In function 'std::vector<int> construct_permutation(long long int)':
perm.cpp:43:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |     while (it+1<digits.size())
      |            ~~~~^~~~~~~~~~~~~~
perm.cpp:55:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     if (it<digits.size())
      |         ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...