結果

問題 No.392 2分木をたどれ
ユーザー ichibanshiboriichibanshibori
提出日時 2016-08-19 18:15:47
言語 F#
(F# 4.0)
結果
AC  
実行時間 100 ms / 2,000 ms
コード長 995 bytes
コンパイル時間 6,087 ms
コンパイル使用メモリ 185,636 KB
実行使用メモリ 35,200 KB
最終ジャッジ日時 2024-04-25 08:06:19
合計ジャッジ時間 6,943 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
30,720 KB
testcase_01 AC 100 ms
35,200 KB
testcase_02 AC 98 ms
35,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (204 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

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 ()
0