結果

問題 No.566 だいたい完全二分木
ユーザー tsuchinagatsuchinaga
提出日時 2019-03-07 17:41:03
言語 Go
(1.22.1)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 473 bytes
コンパイル時間 12,074 ms
コンパイル使用メモリ 212,864 KB
実行使用メモリ 8,408 KB
最終ジャッジ日時 2023-09-05 19:26:41
合計ジャッジ時間 12,161 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
5,708 KB
testcase_09 AC 5 ms
8,240 KB
testcase_10 AC 9 ms
8,408 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var k int
	_, _ = fmt.Scan(&k)
	max := int(math.Pow(2, float64(k))) - 1
	root := int(math.Pow(2, float64(k-1))) + 1

	a := fmt.Sprintf("%d ", root)
	for i := 0; i < k; i++ {
		p := int(math.Pow(2, float64(k-i-1)))
		for j := 0; j < int(math.Pow(2, float64(i))); j++ {
			q := p + p*2*j
			if 1 <= q && q <= max && q != root {
				a += fmt.Sprintf("%d ", q)
			}
		}
	}
	fmt.Println(strings.Trim(a, " "))
}
0