結果
| 問題 |
No.392 2分木をたどれ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-08-19 18:15:47 |
| 言語 | F# (F# 4.0) |
| 結果 |
AC
|
| 実行時間 | 118 ms / 2,000 ms |
| コード長 | 995 bytes |
| コンパイル時間 | 7,098 ms |
| コンパイル使用メモリ | 194,992 KB |
| 実行使用メモリ | 35,328 KB |
| 最終ジャッジ日時 | 2024-11-07 18:27:36 |
| 合計ジャッジ時間 | 8,076 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (234 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/
ソースコード
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 ()