#include <bits/stdc++.h> using namespace std; int n, k, m, t[2000111]; int main () { scanf("%d%d", &n, &k); m = 1; while (n--) m <<= 1; for (int i = 0; i < m; i++) scanf("%d", &t[i]); if ((k & 1) == 0) for (int i = 0; i < m; i++) printf("%d ", t[i]); else for (int i = m - 1; i >= 0; i--) printf("%d ", t[i]); printf("\n"); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | #include <bits/stdc++.h> using namespace std; int n, k, m, t[2000111]; int main () { scanf("%d%d", &n, &k); m = 1; while (n--) m <<= 1; for (int i = 0; i < m; i++) scanf("%d", &t[i]); if ((k & 1) == 0) for (int i = 0; i < m; i++) printf("%d ", t[i]); else for (int i = m - 1; i >= 0; i--) printf("%d ", t[i]); printf("\n"); return 0; } |