結果

問題 No.401 数字の渦巻き
ユーザー abL8ZLsTbFabL8ZLsTbF
提出日時 2016-07-28 15:47:40
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 916 bytes
コンパイル時間 3,282 ms
コンパイル使用メモリ 102,496 KB
実行使用メモリ 23,200 KB
最終ジャッジ日時 2023-08-06 15:05:07
合計ジャッジ時間 6,527 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
21,224 KB
testcase_01 AC 62 ms
21,176 KB
testcase_02 AC 62 ms
21,232 KB
testcase_03 AC 62 ms
21,188 KB
testcase_04 AC 61 ms
21,184 KB
testcase_05 AC 62 ms
21,068 KB
testcase_06 AC 62 ms
21,160 KB
testcase_07 AC 61 ms
21,108 KB
testcase_08 AC 63 ms
21,116 KB
testcase_09 AC 62 ms
23,200 KB
testcase_10 AC 62 ms
21,192 KB
testcase_11 AC 62 ms
21,208 KB
testcase_12 AC 62 ms
21,188 KB
testcase_13 AC 63 ms
21,240 KB
testcase_14 AC 63 ms
23,164 KB
testcase_15 AC 62 ms
21,036 KB
testcase_16 AC 63 ms
21,068 KB
testcase_17 AC 63 ms
21,104 KB
testcase_18 AC 65 ms
21,128 KB
testcase_19 AC 63 ms
21,192 KB
testcase_20 AC 64 ms
21,184 KB
testcase_21 AC 63 ms
21,096 KB
testcase_22 AC 64 ms
23,132 KB
testcase_23 AC 63 ms
19,024 KB
testcase_24 AC 65 ms
21,008 KB
testcase_25 AC 64 ms
21,104 KB
testcase_26 AC 65 ms
21,072 KB
testcase_27 AC 65 ms
21,240 KB
testcase_28 AC 64 ms
19,188 KB
testcase_29 AC 65 ms
21,120 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 Program
{
	public static void Main()
	{
		int N = int.Parse(Console.ReadLine());
		int[,] grid = new int[N, N];
		int[,] move = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
		int[] pos = {0, 0};
		int moveId = 0;
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N; j++)
			{
				grid[i, j] = 0;
			}
		}
		for (int i = 1; i <= N * N; i++)
		{
			grid[pos[0], pos[1]] = i;
			if (pos[0] + move[moveId, 0] < 0 || N <= pos[0] + move[moveId, 0] ||
				pos[1] + move[moveId, 1] < 0 || N <= pos[1] + move[moveId, 1] ||
				grid[pos[0] + move[moveId, 0], pos[1] + move[moveId, 1]] > 0)
			{
				moveId = (moveId + 1) % 4;
			}
			pos[0] += move[moveId, 0];
			pos[1] += move[moveId, 1];
		}
		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < N; j++)
			{
				Console.Write("{0:000}", grid[j, i]);
				if (j < N - 1)
				{
					Console.Write(' ');
				}
			}
			Console.WriteLine();
		}
	}
}
0