#include <stdio.h> using namespace std; int pot(int a, int b) { if (b == 0) return 1; if (b % 2) return a * pot(a, b-1); else return pot(a, b/2)*pot(a, b/2); } int tab[1200000]; int main() { int n, t; scanf("%d %d", &n, &t); int ind = pot(2, n); for (int i = 0; i < ind; i++) scanf("%d", &tab[i]); if (t % 2) for (int i = ind - 1; i >= 0; i--) printf("%d ", tab[i]); else for (int i = 0; i < ind; i++) printf("%d ", tab[i]); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> using namespace std; int pot(int a, int b) { if (b == 0) return 1; if (b % 2) return a * pot(a, b-1); else return pot(a, b/2)*pot(a, b/2); } int tab[1200000]; int main() { int n, t; scanf("%d %d", &n, &t); int ind = pot(2, n); for (int i = 0; i < ind; i++) scanf("%d", &tab[i]); if (t % 2) for (int i = ind - 1; i >= 0; i--) printf("%d ", tab[i]); else for (int i = 0; i < ind; i++) printf("%d ", tab[i]); return 0; } |