fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4. #pragma warning (disable: 4996)
  5.  
  6. long long N, X; bool used[1 << 19];
  7. vector<long long>E;
  8.  
  9. int main() {
  10. cin >> N >> X;
  11. if (X >= (1LL << N)) {
  12. for (int i = 0; i < (1 << N); i++) E.push_back(i);
  13. }
  14. else {
  15. for (int i = 0; i < (1 << N); i++) {
  16. if (used[i] == true) continue;
  17. E.push_back(i);
  18. used[i] = true; used[i^X] = true;
  19. }
  20. }
  21.  
  22. cout << (int)E.size() - 1 << endl;
  23. for (int i = 0; i < (int)E.size() - 1; i++) { if (i) printf(" "); printf("%d", (E[i + 1] ^ E[i])); } printf("\n");
  24. return 0;
  25. }
Success #stdin #stdout 0s 15752KB
stdin
3 7
stdout
3
1 3 1