結果

問題 No.401 数字の渦巻き
ユーザー AreTrashAreTrash
提出日時 2016-07-13 14:12:41
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,481 bytes
コンパイル時間 1,103 ms
コンパイル使用メモリ 115,100 KB
実行使用メモリ 29,388 KB
最終ジャッジ日時 2024-04-23 15:09:53
合計ジャッジ時間 3,073 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

namespace Ex160701{
    public class Program{
        public static void Main(string[] args){
            var N = 1;
            var res = new int[N, N].ToJaggedArray();
            res[0][0] = 1;

            Func<int, int, bool> isInside = (tx, ty) => 0 <= tx && tx < N && 0 <= ty && ty < N;
            var c = 1;
            var d = 0;
            var dx = new[]{1, 0, -1, 0};
            var dy = new[]{0, 1, 0, -1};
            var x = 0;
            var y = 0;

            for(var i = 0; i < N * N; i++){
                for(var j = 0; j < 2; j++, d++) {
                    var nx = x + dx[d % 4];
                    var ny = y + dy[d % 4];

                    if(isInside(nx, ny) && res[ny][nx] == 0) {
                        res[y = ny][x = nx] = ++c;
                        break;
                    }
                }
            }

            foreach(var r in res){
                Console.WriteLine(string.Join(" ", r.Select(i => i.ToString("00"))));
            }
        }
    }

    public static class ExMethod{
        public static T[][] ToJaggedArray<T>(this T[,] src){
            var x = src.GetLength(1);
            var y = src.GetLength(0);
            var ret = new T[y][];

            for(var i = 0; i < y; i++){
                ret[i] = new T[x];
                for(var j = 0; j < x; j++){
                    ret[i][j] = src[i, j];
                }
            }

            return ret;
        } 
    }
}
0