//Autor: Mateusz Wasylkiewicz
//Zawody: Potyczki Algorytmiczne 2016
//Strona: http://potyczki.mimuw.edu.pl/
//Zadanie: Tasowanie, runda 1B
//Czas: Theta(2^n)
#include <bits/stdc++.h>
using namespace std;
#define FORD(x, a, b) for (int x = (a); x >= (b); x--)
#define REP(x, n) for (int x = 0; x < (n); x++)
const int MAX_N = 20;
int n, t, a[(1 << MAX_N) + 100];
void wczytaj_dane()
{
cin >> n >> t;
REP(i, 1 << n)
cin >> a[i];
}
void rozwiaz()
{
if (t % 2 == 0)
REP(i, 1 << n)
cout << a[i] << ' ';
else
FORD(i, (1 << n) - 1, 0)
cout << a[i] << ' ';
cout << '\n';
}
void zrob_test()
{
wczytaj_dane();
rozwiaz();
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
zrob_test();
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 | //Autor: Mateusz Wasylkiewicz //Zawody: Potyczki Algorytmiczne 2016 //Strona: http://potyczki.mimuw.edu.pl/ //Zadanie: Tasowanie, runda 1B //Czas: Theta(2^n) #include <bits/stdc++.h> using namespace std; #define FORD(x, a, b) for (int x = (a); x >= (b); x--) #define REP(x, n) for (int x = 0; x < (n); x++) const int MAX_N = 20; int n, t, a[(1 << MAX_N) + 100]; void wczytaj_dane() { cin >> n >> t; REP(i, 1 << n) cin >> a[i]; } void rozwiaz() { if (t % 2 == 0) REP(i, 1 << n) cout << a[i] << ' '; else FORD(i, (1 << n) - 1, 0) cout << a[i] << ' '; cout << '\n'; } void zrob_test() { wczytaj_dane(); rozwiaz(); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); zrob_test(); return 0; } |
English