結果

問題 No.566 だいたい完全二分木
ユーザー GrenacheGrenache
提出日時 2017-09-08 23:05:20
言語 Java21
(openjdk 21)
結果
AC  
実行時間 149 ms / 2,000 ms
コード長 1,032 bytes
コンパイル時間 3,978 ms
コンパイル使用メモリ 79,216 KB
実行使用メモリ 41,540 KB
最終ジャッジ日時 2024-04-24 20:56:15
合計ジャッジ時間 6,403 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 117 ms
40,056 KB
testcase_01 AC 131 ms
41,232 KB
testcase_02 AC 124 ms
41,148 KB
testcase_03 AC 115 ms
40,124 KB
testcase_04 AC 115 ms
40,268 KB
testcase_05 AC 130 ms
41,368 KB
testcase_06 AC 121 ms
40,120 KB
testcase_07 AC 135 ms
40,248 KB
testcase_08 AC 134 ms
40,368 KB
testcase_09 AC 142 ms
41,312 KB
testcase_10 AC 149 ms
41,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder566 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int k = sc.nextInt();

		int n = 1;
		for (int i = 0; i < k; i++) {
			n *= 2;
		}

		List<Integer> ans = new ArrayList<>(n);
		ans.add(n - 1);
		int base = 2;
		for (int i = 0; i < k - 1; i++) {
			for (int j = 1; j < base; j += 2) {
				ans.add(n / base * j);
			}

			base *= 2;
		}

		for (int i = 1; i < n - 1; i += 2) {
			ans.add(i);
		}

//		pr.println(ans);
//		pr.println(ans.size());
//		pr.println(n);
		for (int i = 0, size = ans.size(); i < size; i++) {
			if (i > 0) {
				pr.print(' ');
			}
			pr.print(ans.get(i));
		}
		pr.println();
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0