結果

問題 No.401 数字の渦巻き
ユーザー bluemeganebluemegane
提出日時 2018-09-18 10:52:32
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,271 bytes
コンパイル時間 2,119 ms
コンパイル使用メモリ 102,816 KB
実行使用メモリ 23,272 KB
最終ジャッジ日時 2023-09-25 09:43:11
合計ジャッジ時間 5,598 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
19,204 KB
testcase_01 AC 62 ms
21,048 KB
testcase_02 AC 63 ms
23,116 KB
testcase_03 AC 63 ms
21,248 KB
testcase_04 AC 62 ms
21,120 KB
testcase_05 AC 63 ms
23,172 KB
testcase_06 AC 62 ms
19,132 KB
testcase_07 AC 64 ms
23,132 KB
testcase_08 AC 64 ms
21,136 KB
testcase_09 AC 64 ms
21,120 KB
testcase_10 AC 62 ms
21,068 KB
testcase_11 AC 62 ms
21,256 KB
testcase_12 AC 63 ms
21,136 KB
testcase_13 AC 63 ms
21,252 KB
testcase_14 AC 62 ms
21,080 KB
testcase_15 AC 62 ms
21,084 KB
testcase_16 AC 62 ms
23,104 KB
testcase_17 AC 62 ms
21,148 KB
testcase_18 AC 62 ms
21,140 KB
testcase_19 AC 63 ms
21,176 KB
testcase_20 AC 64 ms
21,140 KB
testcase_21 AC 64 ms
23,044 KB
testcase_22 AC 62 ms
19,156 KB
testcase_23 AC 63 ms
19,176 KB
testcase_24 AC 63 ms
21,096 KB
testcase_25 AC 64 ms
23,272 KB
testcase_26 AC 63 ms
21,132 KB
testcase_27 AC 64 ms
21,072 KB
testcase_28 AC 64 ms
21,132 KB
testcase_29 AC 64 ms
23,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var map = new string[n, n];
        putMap(map, n);
        print(map, n);
    }
    public static void print(string[,] map, int n)
    {
        var ans = new string[n];
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
                ans[j] = map[i, j];
            Console.WriteLine(string.Join(" ", ans));
        }
    }
    public static void putMap(string[,] map, int n)
    {
        int[] dx = { 0, 1, 0, -1 };
        int[] dy = { 1, 0, -1, 0 };
        var used = new bool[n, n];
        var x = 0; var y = 0; var dir = 0;
        var p = 1;
        var cango = true;
        while (cango)
        {
            used[x, y] = true;
            map[x, y] = string.Format("{0:000}", p++);
            cango = false;
            for (int i = 0; i < 4; i++)
            {
                var te = dir + i;
                if (te >= 4) te -= 4;
                var nx = x + dx[te];
                var ny = y + dy[te];
                if (nx >= 0 && nx < n && ny >= 0 && ny < n && !used[nx, ny])
                { x = nx; y = ny; dir = te; cango = true; break; }
            }
        }
    }
}
0