fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef vector<bool> vb;
  5. typedef vector<vb> vvb;
  6. typedef vector<int> vi;
  7. typedef vector<vi> vvi;
  8. typedef vector<ll> vl;
  9. typedef vector<vl> vvl;
  10. typedef vector<char> vc;
  11. typedef vector<vc> vvc ;
  12. typedef vector<string> vs;
  13. typedef vector<pair<ll, ll> > vp;
  14. typedef pair<ll, ll> pl;
  15.  
  16. #define endl "\n"
  17. #define pb push_back
  18. #define F first
  19. #define S second
  20. #define all(v) v.begin(), v.end()
  21. #define rall(v) v.rbegin(), v.rend()
  22. #define sz(a) int(a.size())
  23. const ll mod = 1e9+7;
  24.  
  25. set<pair<ll, string>> capic;
  26. vs capc;
  27. ll n, orgn, s, as;
  28. string cad;
  29.  
  30. void capi(ll idx){
  31. if(idx==as){
  32. ll val=0;
  33.  
  34. if(cad[0]=='0')
  35. return;
  36.  
  37. string aux = cad;
  38. reverse(all(aux));
  39.  
  40. vs cads;
  41.  
  42. if(orgn&1){
  43. cads.pb(cad+"1"+aux);
  44. cads.pb(cad+"0"+aux);
  45.  
  46. } else {
  47. cads.pb(cad+aux);
  48. }
  49.  
  50. for(auto cade: cads){
  51. val=0;
  52. for(ll i=sz(cade)-1, j=0; i>=0; i--, j++){
  53. if(cade[i]=='1')
  54. val += (1ll<<j);
  55. }
  56.  
  57. capic.insert(pair<ll, string>(val, cade));
  58. }
  59.  
  60. return;
  61. }
  62.  
  63. capi(idx+1);
  64. cad[idx]='1';
  65.  
  66. capi(idx+1);
  67. cad[idx]='0';
  68.  
  69. }
  70.  
  71. void prec(){
  72. for(s=1; s<=32; s++){
  73. if(s==1){
  74. capic.insert(pair<ll, string>(1, "1"));
  75. continue;
  76. }
  77.  
  78. orgn=s;
  79. as = s/2;
  80.  
  81. cad="";
  82. for(ll i=0; i<as; i++){
  83. cad+="0";
  84. }
  85.  
  86. capi(0);
  87. }
  88.  
  89. for(auto e: capic)
  90. capc.pb(e.S);
  91. }
  92.  
  93. void solve(){
  94. ll q;
  95.  
  96. cin >> q;
  97.  
  98. cout << capc[--q] << endl;
  99.  
  100.  
  101.  
  102. }
  103.  
  104. int main(){
  105. ios::sync_with_stdio(false);
  106. cin.tie(nullptr);
  107.  
  108. prec();
  109.  
  110. int tt=1;
  111.  
  112. // cin >> tt;
  113.  
  114. while(tt--){
  115. solve();
  116. }
  117. }
Success #stdin #stdout 0.15s 29504KB
stdin
4
stdout
111