Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define F first
  6. #define S second
  7.  
  8. typedef long long ll;
  9.  
  10. int n, x;
  11. bool used[1000005];
  12. vector < int > ans;
  13.  
  14. int main () {
  15. ios_base::sync_with_stdio(0);
  16. #ifdef LOCAL
  17. freopen("input.txt", "r", stdin);
  18. freopen("output.txt", "w", stdout);
  19. #endif // LOCAL
  20. cin >> n >> x;
  21. if (n == 2 && x == 0) {
  22. cout << "NO";
  23. return 0;
  24. }
  25. int f = 0;
  26. if (n % 4 == 1) {
  27. ans.push_back(x);
  28. used[x] = 1;
  29. f = 1;
  30. }
  31. if (n % 4 == 2) {
  32. ans.push_back(0);
  33. ans.push_back(x);
  34. used[x] = 1;
  35. used[0] = 1;
  36. f = 1;
  37. }
  38. if (n % 4 == 3) {
  39. for (int i = 0 ; i <= 20 ; i++) {
  40. if (f)
  41. break;
  42. for (int q = i + 1; q <= 20 ; q++) {
  43. int a = x ^ (1 << i);
  44. int b = x ^ (1 << q);
  45. int c = x ^ (1 << i) ^ (1 << q);
  46. if (a != b && a != c && c != b && a <= 1e6 && b <= 1e6 && c <= 1e6 && !used[a] && !used[b] && !used[c]) {
  47. ans.push_back(a);
  48. ans.push_back(b);
  49. ans.push_back(c);
  50. used[a] = 1;
  51. used[b] = 1;
  52. used[c] = 1;
  53. f = 1;
  54. break;
  55. }
  56. }
  57. }
  58. }
  59. if (n % 4 == 0) {
  60. for (int i = 0 ; i <= 20 ; i++) {
  61. if (f)
  62. break;
  63. for (int q = i + 1; q <= 20 ; q++) {
  64. int a = (1 << i);
  65. int b = (1 << q);
  66. int c = a ^ b;
  67. if (a != b && a != c && c != b && a <= 1e6 && b <= 1e6 && c <= 1e6 && !used[a] && !used[b] && !used[c]) {
  68. ans.push_back(a);
  69. ans.push_back(b);
  70. ans.push_back(c);
  71. ans.push_back(x);
  72. used[a] = 1;
  73. used[b] = 1;
  74. used[c] = 1;
  75. used[x] = 1;
  76. f = 1;
  77. break;
  78. }
  79. }
  80. }
  81. }
  82. int j = 4;
  83. while (n > 4) {
  84. if (used[j] | used[j + 1] | used[j + 2] | used[j + 3]) {
  85. j += 4;
  86. continue;
  87. }
  88. for (int i = 0 ; i < 4 ; i++) {
  89. used[j + i] = 1;
  90. ans.push_back(j + i);
  91. }
  92. j += 4;
  93. n -= 4;
  94. }
  95. j -= 4;
  96. if (!f)
  97. cout << "NO";
  98. else {
  99. cout << "YES\n";
  100. for (int i = 0 ; i < ans.size() ; i++)
  101. cout << ans[i] << " " ;
  102. }
  103. return 0;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement