結果

問題 No.401 数字の渦巻き
ユーザー 37zigen37zigen
提出日時 2016-07-23 00:48:17
言語 Java19
(openjdk 21)
結果
AC  
実行時間 279 ms / 2,000 ms
コード長 774 bytes
コンパイル時間 3,839 ms
コンパイル使用メモリ 75,432 KB
実行使用メモリ 64,000 KB
最終ジャッジ日時 2023-08-06 10:30:51
合計ジャッジ時間 10,171 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
55,716 KB
testcase_01 AC 131 ms
55,456 KB
testcase_02 AC 138 ms
55,704 KB
testcase_03 AC 137 ms
56,052 KB
testcase_04 AC 141 ms
55,824 KB
testcase_05 AC 141 ms
56,008 KB
testcase_06 AC 144 ms
55,644 KB
testcase_07 AC 154 ms
55,712 KB
testcase_08 AC 152 ms
55,892 KB
testcase_09 AC 154 ms
55,832 KB
testcase_10 AC 161 ms
55,652 KB
testcase_11 AC 171 ms
54,164 KB
testcase_12 AC 172 ms
55,652 KB
testcase_13 AC 185 ms
56,144 KB
testcase_14 AC 189 ms
58,148 KB
testcase_15 AC 191 ms
56,172 KB
testcase_16 AC 187 ms
55,600 KB
testcase_17 AC 201 ms
55,904 KB
testcase_18 AC 202 ms
56,248 KB
testcase_19 AC 201 ms
56,096 KB
testcase_20 AC 203 ms
56,508 KB
testcase_21 AC 204 ms
56,108 KB
testcase_22 AC 205 ms
56,532 KB
testcase_23 AC 208 ms
56,176 KB
testcase_24 AC 214 ms
54,696 KB
testcase_25 AC 227 ms
56,140 KB
testcase_26 AC 226 ms
58,032 KB
testcase_27 AC 232 ms
55,984 KB
testcase_28 AC 247 ms
56,688 KB
testcase_29 AC 279 ms
64,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solver();
	}

	static void solver() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] table = new int[n][n];
		int d = 0;
		int now = 1;
		int x = 0, y = 0;
		int[] dx = { 1, 0, -1, 0 };
		int[] dy = { 0, 1, 0, -1 };

		while (true) {
			if (x >= n || y >= n)
				break;
			if (table[x][y] != 0)
				break;
			table[x][y] = now;
			now++;
			if (x + dx[d] >= n || y + dy[d] >= n || x + dx[d] < 0 || y + dy[d] < 0 || table[x + dx[d]][y + dy[d]] != 0)
				d = (d + 1) % 4;
			x += dx[d];
			y += dy[d];

		}
		for (int j = 0; j < n; j++) {
			for (int i = 0; i < n; i++) {
				System.out.printf("%03d" + (i == n - 1 ? "\n" : " "), table[i][j]);
			}
		}

	}
}
0