結果

問題 No.566 だいたい完全二分木
ユーザー toyuzukotoyuzuko
提出日時 2020-09-08 22:59:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 369 bytes
コンパイル時間 364 ms
コンパイル使用メモリ 10,624 KB
実行使用メモリ 8,648 KB
最終ジャッジ日時 2023-08-20 10:11:29
合計ジャッジ時間 1,533 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,828 KB
testcase_01 AC 16 ms
7,832 KB
testcase_02 AC 15 ms
7,880 KB
testcase_03 AC 15 ms
7,868 KB
testcase_04 AC 16 ms
7,800 KB
testcase_05 AC 16 ms
7,820 KB
testcase_06 AC 16 ms
7,924 KB
testcase_07 AC 16 ms
7,872 KB
testcase_08 AC 17 ms
8,340 KB
testcase_09 AC 18 ms
8,552 KB
testcase_10 AC 20 ms
8,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

K = int(input())

stack = [((1 << (K - 1)) + 1, K - 2)]
res = [(1 << (K - 1)) + 1]

while stack:
    n, d = stack.pop()
    n -= 1
    lt = n - (1 << d)
    rt = n + (1 << d)
    res.append(lt + 1)
    if rt + 1 != (1 << K):
        res.append(rt + 1)
    if d > 0:
        stack.append((rt + 1, d - 1))
        stack.append((lt + 1, d - 1))

res.append(1)

print(*res)
0