結果

問題 No.566 だいたい完全二分木
ユーザー fjafjafja
提出日時 2017-09-10 00:11:05
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 616 bytes
コンパイル時間 3,606 ms
コンパイル使用メモリ 76,460 KB
実行使用メモリ 42,592 KB
最終ジャッジ日時 2024-11-07 10:20:26
合計ジャッジ時間 7,712 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

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+" ");
		}
		System.out.println();


	}


	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