結果
| 問題 |
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 () |> int
let maxN = N * N
let field = Array2D.zeroCreate<int> N N
let 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 + dy
nx >=0 && nx < N && ny >= 0 && ny < N && field.[ny, nx] = 0
let rec move x y n dir =
if n > maxN then ()
else
field.[y, x] <- n
let nextDir =
if canMove x y dir
then dir
else (dir + 1) % 4
let dx, dy = dxy.[nextDir]
move (x + dx) (y + dy) (n + 1) nextDir
move 0 0 1 0
let 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 ()