結果

問題 No.566 だいたい完全二分木
ユーザー fjafjafjafjafjafja
提出日時 2017-09-10 00:12:26
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 611 bytes
コンパイル時間 3,715 ms
コンパイル使用メモリ 76,456 KB
実行使用メモリ 42,336 KB
最終ジャッジ日時 2024-04-25 00:55:58
合計ジャッジ時間 6,597 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class N566 {
	static int[] h;
	static int K;

	public static void main(String[] args)
	{
		Scanner sc=new Scanner (System.in);
		K=sc.nextInt();
		int p=(int)Math.pow(2, K);

		h=new int[p-1];
		h[0]=p/2;
		tree(p/2,0,1);

		for(int ans:h)
		{
			System.out.print(ans+" ");
		}

	}


	static void tree(int p,int k,int rank)
	{
		h[k]=p;
		//if((int)Math.pow(2, K-1)-1<=k||k<=(int)Math.pow(2,K)-2)
		if(rank==K)
		{
			return;
		}
		else
		{
			rank++;
			tree(p-(int)Math.pow(2, K-rank),2*k+1,rank);
			tree(p+(int)Math.pow(2,K-rank),2*k+2,rank);
		}
	}

}
0