結果
問題 | No.401 数字の渦巻き |
ユーザー |
|
提出日時 | 2016-08-07 23:37:36 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 343 ms / 2,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 9,551 ms |
コンパイル使用メモリ | 196,076 KB |
実行使用メモリ | 35,440 KB |
最終ジャッジ日時 | 2024-11-07 09:59:19 |
合計ジャッジ時間 | 21,304 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (679 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 N = stdin.ReadLine () |> intlet maxN = N * Nlet field = Array2D.zeroCreate<int> N Nlet dxy = [| (1, 0); (0, 1); (-1, 0); (0, -1) |]let canMove x y dir =let dx, dy = dxy.[dir]let nx, ny = x + dx, y + dynx >=0 && nx < N && ny >= 0 && ny < N && field.[ny, nx] = 0let rec move x y n dir =if n > maxN then ()elsefield.[y, x] <- nlet nextDir =if canMove x y dirthen direlse (dir + 1) % 4let dx, dy = dxy.[nextDir]move (x + dx) (y + dy) (n + 1) nextDirmove 0 0 1 0let formatLine y =seq {for x in 0..(N - 1) -> sprintf "%03d" field.[y, x]} |>Seq.reduce (fun s1 s2 -> s1 + " " + s2)seq {for y in 0..(N - 1) -> formatLine y} |> Seq.iter (printfn "%s")doIt ()