結果

問題 No.566 だいたい完全二分木
ユーザー titia
提出日時 2024-05-02 01:58:27
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 282 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 70,528 KB
最終ジャッジ日時 2024-11-22 11:25:51
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

from random import shuffle

K=int(input())

LIST=list(range(1,2**K))
shuffle(LIST)

def height(LIST):
    H=[0]*(len(LIST)+1)
    LEFT=[-1]*(len(LIST)+1)
    RIGHT=[-1]*(len(LIST)+1)

    for i in range(1,len(LIST)):
        now=0
        h=1
        while True:
            if LIST[i]<LIST[now]:
                if LEFT[now]==-1:
                    LEFT[now]=i
                    H[i]=h
                    break
                else:
                    h+=1
                    now=LEFT[now]
            else:
                if RIGHT[now]==-1:
                    RIGHT[now]=i
                    H[i]=h
                    break
                else:
                    h+=1
                    now=RIGHT[now]

    return max(H)

while True:
    shuffle(LIST)

    if K<=height(LIST)<=3*K:
        print(*LIST)
        break
                
                    
            
0