結果
問題 |
No.566 だいたい完全二分木
|
ユーザー |
![]() |
提出日時 | 2020-04-12 16:05:28 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 53 ms / 2,000 ms |
コード長 | 827 bytes |
コンパイル時間 | 359 ms |
コンパイル使用メモリ | 82,188 KB |
実行使用メモリ | 65,024 KB |
最終ジャッジ日時 | 2024-09-22 02:41:26 |
合計ジャッジ時間 | 1,477 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 11 |
ソースコード
import math,sys K=int(input()) v=2**(K-1)+1 P=[str(v)] left=[str(i) for i in range(1,v)] right=[str(i) for i in range(v+1,2**K)] def f(list): if len(list)==0: return [] elif len(list)==1: return [list[0]] else: index=len(list)//2 return [list[index],list[0:index],list[index+1:]] que=[left,right] while len(P)!=2**K-1: if len(que)<=1: print('error') else: l=que.pop(0) r=que.pop(0) tmp1=f(l) tmp2=f(r) if len(tmp1)==3: v1,l1,r1=tmp1[0],tmp1[1],tmp1[2] P.append(str(v1)) que.append(l1) que.append(r1) if len(tmp2)==3: v2,l2,r2=tmp2[0],tmp2[1],tmp2[2] P.append(str(v2)) que.append(l2) que.append(r2) if len(tmp1)==1: P.append(str(tmp1[0])) if len(tmp2)==1: P.append(str(tmp2[0])) print(' '.join(P))