// Author: Krzysztof Bochenek // Email: kpbochenek@gmail.com // -------------------------------- #include <stdio.h> #include <vector> #include <map> #include <set> #include <stack> #include <math.h> #include <algorithm> #include <string> #include <iostream> typedef long long int ll; typedef unsigned long long ull; using namespace std; void reverse_print(int *A, int left, int right) { if (right - left > 1) { int middle = (right + left) / 2; reverse_print(A, middle, right); reverse_print(A, left, middle); } else { cout << A[left] << " "; } } int main() { int n, t, nsize; cin >> n >> t; nsize = pow(2, n); int A[nsize]; for (int i=0; i<nsize; ++i) { cin >> A[i]; } if (t % 2 == 0) { for (int i=0; i<nsize; ++i) { cout << A[i] << " "; } cout << endl; } else { reverse_print(A, 0, nsize); cout << endl; } return 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 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 | // Author: Krzysztof Bochenek // Email: kpbochenek@gmail.com // -------------------------------- #include <stdio.h> #include <vector> #include <map> #include <set> #include <stack> #include <math.h> #include <algorithm> #include <string> #include <iostream> typedef long long int ll; typedef unsigned long long ull; using namespace std; void reverse_print(int *A, int left, int right) { if (right - left > 1) { int middle = (right + left) / 2; reverse_print(A, middle, right); reverse_print(A, left, middle); } else { cout << A[left] << " "; } } int main() { int n, t, nsize; cin >> n >> t; nsize = pow(2, n); int A[nsize]; for (int i=0; i<nsize; ++i) { cin >> A[i]; } if (t % 2 == 0) { for (int i=0; i<nsize; ++i) { cout << A[i] << " "; } cout << endl; } else { reverse_print(A, 0, nsize); cout << endl; } return 0; } |