結果

問題 No.401 数字の渦巻き
ユーザー ichibanshiboriichibanshibori
提出日時 2016-08-07 23:37:36
言語 F#
(F# 4.0)
結果
AC  
実行時間 334 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 10,201 ms
コンパイル使用メモリ 185,480 KB
実行使用メモリ 35,464 KB
最終ジャッジ日時 2024-04-25 00:34:51
合計ジャッジ時間 21,055 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 300 ms
34,396 KB
testcase_01 AC 299 ms
34,524 KB
testcase_02 AC 303 ms
35,312 KB
testcase_03 AC 316 ms
35,220 KB
testcase_04 AC 304 ms
34,660 KB
testcase_05 AC 321 ms
34,400 KB
testcase_06 AC 322 ms
35,464 KB
testcase_07 AC 310 ms
35,204 KB
testcase_08 AC 329 ms
35,216 KB
testcase_09 AC 310 ms
35,220 KB
testcase_10 AC 309 ms
35,348 KB
testcase_11 AC 307 ms
34,528 KB
testcase_12 AC 308 ms
35,220 KB
testcase_13 AC 309 ms
34,908 KB
testcase_14 AC 309 ms
34,700 KB
testcase_15 AC 310 ms
35,220 KB
testcase_16 AC 302 ms
35,060 KB
testcase_17 AC 299 ms
34,784 KB
testcase_18 AC 312 ms
34,464 KB
testcase_19 AC 304 ms
35,312 KB
testcase_20 AC 311 ms
35,024 KB
testcase_21 AC 319 ms
35,092 KB
testcase_22 AC 334 ms
35,220 KB
testcase_23 AC 304 ms
34,424 KB
testcase_24 AC 308 ms
34,916 KB
testcase_25 AC 304 ms
35,224 KB
testcase_26 AC 301 ms
35,224 KB
testcase_27 AC 307 ms
34,508 KB
testcase_28 AC 311 ms
34,408 KB
testcase_29 AC 305 ms
34,656 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.fsproj を復元しました (624 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 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 ()
0