結果

問題 No.392 2分木をたどれ
ユーザー roarisroaris
提出日時 2019-08-03 12:39:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 584 bytes
コンパイル時間 121 ms
コンパイル使用メモリ 10,672 KB
実行使用メモリ 8,988 KB
最終ジャッジ日時 2023-09-19 03:25:31
合計ジャッジ時間 844 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
8,796 KB
testcase_01 AC 41 ms
8,988 KB
testcase_02 AC 41 ms
8,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def bfs(start):
    queue = deque([])
    queue.append(start)
    route = [-1] * 4095
    route[0] = ''
    
    while len(queue) > 0:
        current_node = queue.popleft()
        if 2047 <= current_node <= 4094:
            continue
        route[2*current_node+1] = route[current_node] + 'L'
        route[2*current_node+2] = route[current_node] + 'R'
        queue.append(2*current_node+1)
        queue.append(2*current_node+2)
    
    return route

route = bfs(0)
m = int(input())

for _ in range(m):
    A_i = int(input())
    print(route[A_i])
0