ABC126-F : XOR Matching

https://atcoder.jp/contests/abc126/tasks/abc126_f

  • 0부터 $2^M-1$까지 xor하면 0이 된다는 것을 이용한 수학문제. 솔직히 풀이를 딱 알아야만 하기 때문에 노잼..
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <cstdio>
class Problem {
  int M, K;
 public:
  Problem() {
    scanf("%d %d", &M, &K);
  }
  void solve() {
    int bound = 1 << M;
    if (K >= bound || (K == 1 && M == 1)) printf("-1");
    else if (K == 0 && M == 1) printf("0 0 1 1");
    else {
      printf("%d ", K);
      for(int i = 0; i < bound; i++) {
        if(i == K) continue;
        printf("%d ", i);
      }
      printf("%d ", K);
      for(int i = bound-1; i >= 0; i--) {
        if(i == K) continue;
        printf("%d ", i);
      }
    }
  }
};