#include "bits/stdc++.h" using namespace std; int main(){ int n, t; ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> t; vector<int> v(1<<n); for(int i = 0; i < (1<<n); ++i) cin >> v[i]; if(t&1) for(int i = 0; i < (1<<(n-1)); ++i){ int j = ((1<<n)-1) ^ i; swap(v[i], v[j]); } for(int x : v) cout << x << " "; cout << "\n"; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | #include "bits/stdc++.h" using namespace std; int main(){ int n, t; ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> t; vector<int> v(1<<n); for(int i = 0; i < (1<<n); ++i) cin >> v[i]; if(t&1) for(int i = 0; i < (1<<(n-1)); ++i){ int j = ((1<<n)-1) ^ i; swap(v[i], v[j]); } for(int x : v) cout << x << " "; cout << "\n"; } |