제출 #623524

#제출 시각아이디문제언어결과실행 시간메모리
623524Lobo순열 (APIO22_perm)C++17
100 / 100
2 ms352 KiB
#include "perm.h" #include<iostream> #include<vector> #include<deque> #include<math.h> using namespace std; #define pb push_back #define pf push_front #define int long long vector<int32_t> construct_permutation(int k) { vector<int32_t> seq; int lg = 0; for(int i = 0; i <= 60; i++) { if(k >= (1LL<<i)) lg = i; } if(lg < 2) { for(int i = k-2; i >= 0; i--) { seq.pb(i); } return seq; } deque<int> ans; int cur = 0; //do the first 2/3 separate if((1LL<<(lg-1))&k) { //begins with 11 ans.pb(cur++); //10 ans.pf(cur++); //11 //ans = 10 cur = ans.size(); lg-=2; } else if((1LL<<(lg-2))&k){ //begins with 100 ans.pb(cur++); //10 ans.pf(cur++); //11 ans.pf(cur++); //100 ans.pf(cur++); //101 //ans = 3210 cur = ans.size(); lg-=3; } else { //begins with 101 ans.pb(cur++); //10 ans.pf(cur++); //11 ans.pf(cur++); //100 //ans = 210 cur = ans.size(); lg-=3; } //do the rest in groups of 2 while(lg != -1) { if(lg == 0 || ((1LL<<lg)&k) == 0) { //if it is the last or 0 ans.pb(cur++); //_0 if((1LL<<lg)&k) ans.pf(cur++); //_1 lg--; } else if((1LL<<(lg-1))&k) { //it is 11 -> sum 3 ans.pb(cur++); //_0 ans.pb(cur++); //_00 for(int i = 0; i < ans.size(); i++) { if(ans[i] > 1) ans[i]++; } ans.pb(2); //_11 cur++; lg-=2; } else { //it is 10 ans.pb(cur++); //_0 ans.pf(cur++); //_1 ans.pb(cur++); //_10 lg-=2; } } for(auto x : ans) { // cout << " " << x << endl; seq.pb(x); } return seq; } // #include "perm.h" // #include<iostream> // #include<vector> // #include<deque> // #include<math.h> // using namespace std; // #define int long long // vector<int32_t> construct_permutation(int k) // { // int k1 = k; // int k2 = 1; // vector<int> ks; // for(int i = 2; i <= min((int) 8e5,k); i++) { // while(k%i == 0) { // ks.push_back(i); // k/=i; // } // } // ks.push_back(k); // vector<int32_t> vc; // for(auto k1 : ks) { // deque<int> ans; // // int lg = 0; // // for(int i = 0; i <= 60; i++) { // // if(k1 >= (1LL<<i)) lg = i; // // } // int lg = log2(k1); // for(int i = lg-1; i >= 0; i--) { // ans.push_back((int) ans.size()+vc.size()); // if(k1&(1LL<<i)) ans.push_front((int) ans.size()+vc.size()); // } // cout << " " << k1 << endl; // for(auto x : ans) { // // cout << " 1 " << x << endl; // vc.push_back(x); // } // } // return vc; // }

컴파일 시 표준 에러 (stderr) 메시지

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