結果

問題 No.401 数字の渦巻き
ユーザー TatsuDXTatsuDX
提出日時 2016-09-09 00:40:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 3,455 ms
コンパイル使用メモリ 74,648 KB
実行使用メモリ 62,780 KB
最終ジャッジ日時 2023-08-10 00:19:25
合計ジャッジ時間 10,529 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
56,012 KB
testcase_01 AC 125 ms
55,728 KB
testcase_02 AC 126 ms
55,672 KB
testcase_03 AC 131 ms
55,976 KB
testcase_04 AC 130 ms
55,752 KB
testcase_05 AC 132 ms
55,672 KB
testcase_06 AC 139 ms
55,820 KB
testcase_07 AC 146 ms
55,440 KB
testcase_08 AC 146 ms
55,564 KB
testcase_09 AC 149 ms
55,588 KB
testcase_10 AC 152 ms
55,808 KB
testcase_11 AC 163 ms
55,972 KB
testcase_12 AC 165 ms
56,448 KB
testcase_13 AC 177 ms
56,176 KB
testcase_14 AC 177 ms
55,944 KB
testcase_15 AC 183 ms
56,072 KB
testcase_16 AC 186 ms
55,844 KB
testcase_17 AC 193 ms
56,096 KB
testcase_18 AC 194 ms
55,948 KB
testcase_19 AC 203 ms
55,988 KB
testcase_20 AC 201 ms
55,820 KB
testcase_21 AC 203 ms
55,512 KB
testcase_22 AC 217 ms
55,952 KB
testcase_23 AC 204 ms
56,272 KB
testcase_24 AC 205 ms
56,140 KB
testcase_25 AC 221 ms
56,348 KB
testcase_26 AC 224 ms
55,856 KB
testcase_27 AC 225 ms
56,260 KB
testcase_28 AC 228 ms
56,900 KB
testcase_29 AC 258 ms
62,780 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Test {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[][] m = new int[n + 2][n + 2];
		for (int i = 0; i < n + 2; i++) {
			m[0][i] = -1;
			m[n + 1][i] = -1;
			m[i][0] = -1;
			m[i][n + 1] = -1;
		}
		int k = 1, x = 1, y = 1, tx = 0, ty = 1, tmp;
		while (k <= n * n) {
			m[x][y] = k;
			if (m[x + tx][y + ty] != 0) {
				tmp = tx;
				tx = ty;
				ty = -tmp;
			}
			x += tx;
			y += ty;
			k++;
		}
		for (int i = 1; i < n + 1; i++) {
			for (int j = 1; j < n + 1; j++) {
				System.out.printf("%03d", m[i][j]);
				if (j < n) {
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}
0