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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <vector>
#include <algorithm>
#include <iterator>
#include <cstdio>

typedef unsigned int smallnum;

int main() {
  // Step 1. Get the data
  smallnum n, t;
  scanf("%u %u\n", &n, &t);
  smallnum n_pow = (1u << n); // Calculates 2 ** n

  std::vector<smallnum> numbers(n_pow);

  for (smallnum i = 0; i < n_pow; i++) {
    scanf("%u", &numbers[i]);
  }

  // Step 2. Print the data
  if (t % 2 == 0) {
    for (smallnum i = 0; i < numbers.size(); i++) {
      printf("%u", numbers[i]);

      if (i < numbers.size() - 1) {
        printf(" ");
      } else {
        printf("\n");
      }
    }
  } else {
    for (int i = numbers.size() - 1; i >= 0; i--) {
      printf("%u", numbers[i]);

      if (i > 0) {
        printf(" ");
      } else {
        printf("\n");
      }
    }
  }

  return 0;
}