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

using namespace std;

int main() {

    ios::sync_with_stdio(false);
    unsigned int n;
    unsigned int t, i;

    cin >> n;
    cin >> t;

    unsigned int max = 2 << (n - 1);
    unsigned int arr[max];

    for (i = 0; i < max; ++i) {
        cin >> arr[i];
    }

    if (t % 2 == 0) {
        for (i = 0; i < max - 1; ++i) {
            cout << arr[i] << " ";
        }
        cout << arr[max - 1] << endl;
    } else {
        for (i = max - 1; i > 0; --i) {
            cout << arr[i] << " ";
        }
        cout << arr[0] << endl;
    }
    return 0;
}