結果

問題 No.566 だいたい完全二分木
ユーザー takeya_okinotakeya_okino
提出日時 2017-09-20 01:02:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 251 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 79,624 KB
実行使用メモリ 57,764 KB
最終ジャッジ日時 2024-04-25 19:49:44
合計ジャッジ時間 4,368 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
54,232 KB
testcase_01 AC 120 ms
52,908 KB
testcase_02 AC 121 ms
54,072 KB
testcase_03 AC 125 ms
54,008 KB
testcase_04 AC 124 ms
54,248 KB
testcase_05 AC 123 ms
53,376 KB
testcase_06 AC 130 ms
53,896 KB
testcase_07 AC 137 ms
52,968 KB
testcase_08 AC 164 ms
53,128 KB
testcase_09 AC 173 ms
54,464 KB
testcase_10 AC 251 ms
57,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    ArrayList<Integer> ans = func(k);
    for(int i = 0; i < ans.size(); i++) {
      System.out.print(ans.get(i));
      System.out.print(" ");
    }
  }

  public static ArrayList func(int k) {
    ArrayList<Integer> tree = new ArrayList<Integer>();
    if(k == 2) {
      tree.add(1);
      tree.add(2);
      tree.add(3);
      return tree;
    } else {
      ArrayList<Integer> test = func(k - 1);
      tree.add((int)Math.pow(2, k - 1));
      for(int i = 0; i < test.size(); i++) {
        tree.add(test.get(i));
      }
      for(int i = 0; i < test.size(); i++) {
        tree.add(test.get(i) + (int)Math.pow(2, k - 1));
      }
      return tree; 
    }
  }
}
0