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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
//  main.cpp
//  TAS
//
//  Created by Andrzej Michnia on 22.11.2016.
//  Copyright © 2016 intive. All rights reserved.
//

#include <stdio.h>

void tas(unsigned long int left, bool reversed);

unsigned long int pow(unsigned long int base, int pow);

int main(int argc, const char * argv[]) {
    // Declarations
    int n = 20;
    unsigned long int t = 0;
    unsigned long int left = 0;
    
    // Input - length of deck as 2^n, numer of tas as t
    scanf("%d%ld",&n,&t);
    
    // Compute deck length
    left = pow(2,n);
    
    // Do it
    tas(left, (t % 2 == 1));
    printf("\n");
    
    return 0;
}

unsigned long int pow(unsigned long int base, int power) {
    if (power == 0) {
        return 1;
    }
    
    return base * pow(base, power - 1);
}

void tas(unsigned long int left, bool reversed) {
    if (left <= 0) {
        return;
    }
    
    unsigned long int current = 0;
    scanf("%ld",&current);
    
    
    
    if (reversed) {
        tas(left - 1, reversed);
        printf("%ld ", current);
    }
    else {
        printf("%ld ", current);
        tas(left - 1, reversed);
    }
}