import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class tas { public static void main(String[] args) throws IOException { InputScanner is = new InputScanner(); int n = is.nextInt(); int t = is.nextInt(); int tabSize = (int) Math.pow(2, n); int[] tab = new int[tabSize]; for (int i = 0; i < tabSize; i++) tab[i] = is.nextInt(); StringBuffer ans = new StringBuffer(); if (t % 2 == 0) { for (int i = 0; i < tabSize; i++) { ans.append(tab[i]); ans.append(" "); } } else { for (int i = tabSize - 1; i >= 0; i--) { ans.append(tab[i]); ans.append(" "); } } System.out.println(ans); } static class InputScanner { BufferedReader br; StringTokenizer st; public InputScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() throws IOException { if (st == null || !st.hasMoreTokens()) { String line = br.readLine(); st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() throws IOException { String next = next(); return Integer.parseInt(next); } public long nextLong() throws IOException { String next = next(); return Long.parseLong(next); } } }
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 55 56 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class tas { public static void main(String[] args) throws IOException { InputScanner is = new InputScanner(); int n = is.nextInt(); int t = is.nextInt(); int tabSize = (int) Math.pow(2, n); int[] tab = new int[tabSize]; for (int i = 0; i < tabSize; i++) tab[i] = is.nextInt(); StringBuffer ans = new StringBuffer(); if (t % 2 == 0) { for (int i = 0; i < tabSize; i++) { ans.append(tab[i]); ans.append(" "); } } else { for (int i = tabSize - 1; i >= 0; i--) { ans.append(tab[i]); ans.append(" "); } } System.out.println(ans); } static class InputScanner { BufferedReader br; StringTokenizer st; public InputScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } public String next() throws IOException { if (st == null || !st.hasMoreTokens()) { String line = br.readLine(); st = new StringTokenizer(line); } return st.nextToken(); } public int nextInt() throws IOException { String next = next(); return Integer.parseInt(next); } public long nextLong() throws IOException { String next = next(); return Long.parseLong(next); } } } |