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
#include <cstdio>

using namespace std;

const int max_n = 20;
const int max_pow = 1 << max_n;
int numb[max_pow+1];

int main() {
	int n, t;
	scanf("%d %d", &n, &t);

	const int number_cnt = 1<<n;
	const int mask = number_cnt - 1;

	for (int i = 0; i < number_cnt; i++)
		scanf("%d", &numb[i]);

	if (t & 1) {
		printf("%d", numb[mask]);
		for (unsigned int i = 1; i < number_cnt; i++)
			printf(" %d", numb[ mask & (~i)]);
	} else {
		printf("%d", numb[0]);
		for (int i = 1; i < number_cnt; i++)
			printf(" %d", numb[i]);
	}
	printf("\n");

	return 0;
}