bool_bool

codeforces1174D.cpp

Jun 4th, 2019
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define dist2D(x1,y1,x2,y2) ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
  5. #define dist3D(x1,y1,z1,x2,y2,z2) ((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2))
  6. #define EPS 1e-12
  7. #define FastIO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
  8. #define FI freopen("in.txt","r",stdin)
  9. #define FO freopen("out.txt","w",stdout)
  10. #define fap(x) cout<<"WTH: "<<x<<endl
  11. #define ff first
  12. #define fof(i,x,y) for(int i=x;i<(int)y;i++)
  13. #define fob(i,x,y) for(int i=x;i>=(int)y;i--)
  14. #define INF 1000000000
  15. #define ld long double
  16. #define ll long long
  17. #define mem(x,y) memset(x,y,sizeof x)
  18. #define mp make_pair
  19. #define msi map<string,int>
  20. #define mii map<int,int>
  21. #define mis map<int,string>
  22. #define MOD 1000000007
  23. #define PI acos(-1.0)
  24. #define PQ priority_queue
  25. #define pb push_back
  26. #define pib pair<int,bool>
  27. #define pii pair<int,int>
  28. #define pll pair<ll,ll>
  29. #define sfi(x) scanf("%d",&x)
  30. #define sfii(x,y) scanf("%d%d",&x,&y)
  31. #define sfiii(x,y,z) scanf("%d%d%d",&x,&y,&z)
  32. #define siz(x) (int)x.size()
  33. #define sortv(v) sort(v.begin(),v.end())
  34. #define ss second
  35. #define ull unsigned long long
  36. #define umsi unordered_map<string,int>
  37. #define umii unordered_map<int,int>
  38. #define umis unordered_map<int,string>
  39. #define vb vector<bool>
  40. #define vi vector<int>
  41. #define vvi vector<vi>
  42. #define vii vector<pii>
  43. #define vvii vector<vii>
  44. #define vll vector<ll>
  45. #define vpll vector<pll>
  46.  
  47. template<class T> class compare{
  48. public:
  49. bool operator()(pair<T,T> &x,pair<T,T> &y){
  50. if(x.first==y.first){
  51. return x.ss>y.ss;
  52. }
  53. return x.ff>y.ff;
  54. }
  55. };
  56.  
  57. template<class T> ostream& operator<<(ostream &os,const pair<T,T> &a) { os<<a.ff<<" "<<a.ss; }
  58. template<class T> void print(vector<T> &vec){
  59. for(int i=1;i<siz(vec);i++) cout<<vec[i]<<" ";cout<<endl;
  60. }
  61. template<class T> void print(set<T> &s) {
  62. for(auto it: s) cout<<it<<" "; cout<<endl;
  63. }
  64. template<class T> void print(list<T> &lst) {
  65. for(auto it: lst) cout<<it<<" "; cout<<endl;
  66. }
  67. template<class T> ll power(T a,int b){
  68. ll po=1; while(b--) po*=a; return po;
  69. }
  70.  
  71. template<class T> pair<T,T> operator+(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff+b.ff,a.ss+b.ss}; }
  72. template<class T> pair<T,T> operator-(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff-b.ff,a.ss-b.ss}; }
  73. template<class T> pair<T,T> operator*(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff*b.ff,a.ss*b.ss}; }
  74. template<class T> pair<T,T> operator%(const pair<T,T> &a,const pair<T,T> &b){ return {a.ff%b.ff,a.ss%b.ss}; }
  75. template<class T,class U> pair<T,T> operator+(const pair<T,T> &a,const U &b){ return { a.ff+b,a.ss+b}; }
  76. template<class T,class U> pair<T,T> operator*(const pair<T,T> &a,const U &b){ return { a.ff*b,a.ss*b}; }
  77.  
  78. int Set(int N,int pos) { return N=N|(1<<pos); }
  79. int reset(int N,int pos){ return N=N&~(1<<pos);}
  80. bool check(int N,int pos){ return (bool) (N&(1<<pos));}
  81.  
  82. ///=======================================template=======================================//
  83.  
  84. int main()
  85. {
  86. //FI;FO;
  87. FastIO;
  88.  
  89. int n,x; cin>>n>>x;
  90.  
  91. int p=power(2,n);
  92. vb taken(p,false);
  93. vi b;
  94. taken[0]=true;
  95. b.pb(0);
  96.  
  97. for(int i=1;i<p;i++){
  98. //if(i==x) continue;
  99. int xx=i^x;
  100. if(xx>=p){
  101. taken[i]=true;
  102. b.pb(i);
  103. continue;
  104. }
  105. if(!taken[xx]){
  106. taken[i]=true;
  107. b.pb(i);
  108. }
  109. taken[i]=true;
  110. }
  111.  
  112. cout<<siz(b)-1<<endl;
  113.  
  114. for(int i=1;i<siz(b);i++){
  115. cout<<(b[i]^b[i-1])<<" ";
  116. }
  117.  
  118. return 0;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment