結果
問題 | No.392 2分木をたどれ |
ユーザー |
|
提出日時 | 2016-08-19 18:15:47 |
言語 | F# (5.0) |
結果 |
AC
|
実行時間 | 118 ms / 2,000 ms |
コード長 | 995 bytes |
コンパイル時間 | 3,346 ms |
使用メモリ | 21,148 KB |
最終ジャッジ日時 | 2022-12-14 01:23:32 |
合計ジャッジ時間 | 4,470 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 85 ms
17,152 KB |
testcase_01 | AC | 117 ms
21,008 KB |
testcase_02 | AC | 118 ms
21,148 KB |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
let doIt () = let stageNums = [| 0; 2; 6; 14; 30; 62; 126; 254; 510; 1022; 2046; 4094 |] let getPosition num = let stage = Array.findIndex (fun n -> n >= num) stageNums let pos = num - stageNums.[stage - 1] (pos, stageNums.[stage] - stageNums.[stage - 1]) let rec searchPath pos width path = if width <= 1 then path else let nextWidth = width / 2 let nextPos, nextPath = if pos <= nextWidth then pos, "L" else pos - nextWidth, "R" searchPath nextPos nextWidth (nextPath :: path) let doAm num = let pos, width = getPosition num let ans = searchPath pos width [] seq ans |> Seq.rev |> Seq.toArray |> fun arr -> System.String.Join ("", arr) let M = stdin.ReadLine () |> int let ASeq = seq { for _ in 1..M -> stdin.ReadLine () } |> Seq.map int ASeq |> Seq.map doAm |> Seq.iter (printfn "%s") doIt ()