結果

問題 No.401 数字の渦巻き
ユーザー 明智重蔵明智重蔵
提出日時 2016-07-23 18:00:37
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 2,540 bytes
コンパイル時間 2,232 ms
コンパイル使用メモリ 104,084 KB
実行使用メモリ 22,792 KB
最終ジャッジ日時 2023-08-06 11:56:51
合計ジャッジ時間 5,416 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,636 KB
testcase_01 AC 58 ms
20,744 KB
testcase_02 AC 59 ms
20,636 KB
testcase_03 AC 58 ms
22,764 KB
testcase_04 AC 59 ms
18,676 KB
testcase_05 AC 58 ms
20,648 KB
testcase_06 AC 59 ms
20,684 KB
testcase_07 AC 58 ms
20,764 KB
testcase_08 AC 58 ms
20,700 KB
testcase_09 AC 58 ms
22,672 KB
testcase_10 AC 58 ms
20,600 KB
testcase_11 AC 58 ms
20,632 KB
testcase_12 AC 58 ms
22,744 KB
testcase_13 AC 58 ms
20,712 KB
testcase_14 AC 59 ms
20,648 KB
testcase_15 AC 57 ms
20,688 KB
testcase_16 AC 56 ms
18,652 KB
testcase_17 AC 58 ms
20,708 KB
testcase_18 AC 58 ms
22,728 KB
testcase_19 AC 59 ms
20,772 KB
testcase_20 AC 58 ms
20,636 KB
testcase_21 AC 58 ms
20,752 KB
testcase_22 AC 58 ms
22,792 KB
testcase_23 AC 58 ms
20,724 KB
testcase_24 AC 58 ms
20,704 KB
testcase_25 AC 59 ms
20,628 KB
testcase_26 AC 57 ms
20,672 KB
testcase_27 AC 58 ms
22,768 KB
testcase_28 AC 58 ms
20,768 KB
testcase_29 AC 58 ms
18,544 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;

//No401 数字の渦巻き
class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            //001 002 003
            //008 009 004
            //007 006 005
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("4");
            //001 002 003 004
            //012 013 014 005
            //011 016 015 006
            //010 009 008 007
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);
        int UB = N - 1;

        int[,] BanArr = new int[UB + 1, UB + 1];

        int CurrX = 0, CurrY = 0;
        int VisitedCnt = 0;

        //0が右向き
        //1が下向き
        //2が左向き
        //3が上向き
        int Muki = 0;
        while (true) {
            BanArr[CurrX, CurrY] = ++VisitedCnt;
            if (VisitedCnt == (UB + 1) * (UB + 1)) break;

            //次のマスに進む
            while (true) {
                int HeniX, HeniY;
                DeriveHeni(Muki, out HeniX, out HeniY);
                int NewX = CurrX + HeniX;
                int NewY = CurrY + HeniY;
                if (NewX < 0 || UB < NewX
                 || NewY < 0 || UB < NewY
                 || BanArr[NewX, NewY] != 0) {
                    Muki = (Muki + 1) % 4;
                    continue;
                }
                CurrX = NewX; CurrY = NewY;
                break;
            }
        }
        var sb = new System.Text.StringBuilder();
        for (int Y = 0; Y <= UB; Y++) {
            for (int X = 0; X <= UB; X++) {
                if (X > 0) sb.Append(' ');
                sb.Append(BanArr[X, Y].ToString().PadLeft(3, '0'));
            }
            sb.AppendLine();
        }
        Console.Write(sb.ToString());
    }

    //向きを引数として、変位をセット
    static void DeriveHeni(int pMuki, out int pHeniX, out int pHeniY)
    {
        pHeniX = pHeniY = -1;
        if (pMuki == 0) { pHeniX = 1; pHeniY = 0; };
        if (pMuki == 1) { pHeniX = 0; pHeniY = -1; };
        if (pMuki == 2) { pHeniX = -1; pHeniY = 0; };
        if (pMuki == 3) { pHeniX = 0; pHeniY = 1; };
    }
}
0