結果

問題 No.401 数字の渦巻き
ユーザー guriceringuricerin
提出日時 2020-01-23 12:14:01
言語 F#
(F# 4.0)
結果
RE  
実行時間 -
コード長 1,490 bytes
コンパイル時間 5,927 ms
コンパイル使用メモリ 166,884 KB
実行使用メモリ 26,892 KB
最終ジャッジ日時 2023-09-26 06:36:32
合計ジャッジ時間 10,089 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 86 ms
20,840 KB
testcase_02 AC 88 ms
26,892 KB
testcase_03 AC 87 ms
22,964 KB
testcase_04 AC 85 ms
22,920 KB
testcase_05 AC 85 ms
20,968 KB
testcase_06 AC 84 ms
22,980 KB
testcase_07 AC 84 ms
22,884 KB
testcase_08 AC 85 ms
23,072 KB
testcase_09 AC 84 ms
22,808 KB
testcase_10 AC 86 ms
22,748 KB
testcase_11 AC 90 ms
22,880 KB
testcase_12 AC 88 ms
24,936 KB
testcase_13 AC 87 ms
20,968 KB
testcase_14 AC 88 ms
22,872 KB
testcase_15 AC 86 ms
22,940 KB
testcase_16 AC 87 ms
24,936 KB
testcase_17 AC 87 ms
24,776 KB
testcase_18 AC 89 ms
24,856 KB
testcase_19 AC 85 ms
22,816 KB
testcase_20 AC 88 ms
24,932 KB
testcase_21 AC 87 ms
22,820 KB
testcase_22 AC 86 ms
22,876 KB
testcase_23 AC 88 ms
24,924 KB
testcase_24 AC 85 ms
22,844 KB
testcase_25 AC 86 ms
22,864 KB
testcase_26 AC 84 ms
20,776 KB
testcase_27 AC 89 ms
22,888 KB
testcase_28 AC 86 ms
23,068 KB
testcase_29 AC 86 ms
24,916 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

ソースコード

diff #

open System
open System.Collections.Generic

[<AutoOpen>]
module Cin =
    let read f = stdin.ReadLine() |> f
    let reada f = stdin.ReadLine().Split() |> Array.map f
    let readChars() = read string |> Seq.toArray
    let readInts() = readChars() |> Array.map (fun x -> Convert.ToInt32(x.ToString()))

[<AutoOpen>]
module Cout =
    let writer = new IO.StreamWriter(new IO.BufferedStream(Console.OpenStandardOutput()))
    let print (s: string) = writer.Write s
    let println (s: string) = writer.WriteLine s
    let inline puts (s: ^a) = string s |> println

let main() =
    let n = read int
    let maze = Array2D.init n n (fun _ _ -> 0)

    let mutable d = 0

    let nextD() = d <- (d + 1) % 4

    let mutable (x, y) = (0, 0)

    let step x y =
        match d with
        | 0 -> x + 1, y
        | 1 -> x, y + 1
        | 2 -> x - 1, y
        | _ -> x, y - 1

    let isOut x y = not (0 <= x && x < n && 0 <= y && y < n)
    for i in 0 .. n * n - 1 do
        let a = i + 1
        maze.[y, x] <- a
        let mutable (nx, ny) = step x y
        if isOut nx ny then
            nextD()
            let a, b = step x y
            nx <- a
            ny <- b
        if maze.[ny, nx] <> 0 then
            nextD()
            let a, b = step x y
            nx <- a
            ny <- b
        x <- nx
        y <- ny

    for i in 0 .. n - 1 do
        let s = maze.[i, *] |> Array.map (fun x -> sprintf "%03d" x)
        String.Join(" ", s) |> puts

main()
writer.Close()
0