結果

問題 No.566 だいたい完全二分木
ユーザー nebukuro09nebukuro09
提出日時 2017-09-08 22:45:32
言語 Python2
(2.7.18)
結果
AC  
実行時間 18 ms / 2,000 ms
コード長 392 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 6,912 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-24 20:43:09
合計ジャッジ時間 1,265 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
6,784 KB
testcase_01 AC 12 ms
6,784 KB
testcase_02 AC 12 ms
6,784 KB
testcase_03 AC 13 ms
6,656 KB
testcase_04 AC 13 ms
6,656 KB
testcase_05 AC 13 ms
6,784 KB
testcase_06 AC 12 ms
6,656 KB
testcase_07 AC 13 ms
6,656 KB
testcase_08 AC 15 ms
6,912 KB
testcase_09 AC 14 ms
7,040 KB
testcase_10 AC 18 ms
7,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

K = input()
N = 2**K - 1
A = [i for i in xrange(1, N+1)]

ans = [0 for _ in xrange(N)]
p = 0
q = deque()
q.append((0, N))

while len(q) > 0:
    l, r = q.popleft()
    m = (l + r) / 2
    ans[p] = A[m]
    p += 1
    if (r - l > 1):
        q.append((l, m))
        q.append((m+1, r))


ans[N-1], ans[N/2-1] = ans[N/2-1], ans[N-1]
print ' '.join(map(str, ans))
0