結果

問題 No.401 数字の渦巻き
ユーザー TatsuDXTatsuDX
提出日時 2016-09-09 00:40:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 232 ms / 2,000 ms
コード長 711 bytes
コンパイル時間 2,801 ms
コンパイル使用メモリ 77,848 KB
実行使用メモリ 59,408 KB
最終ジャッジ日時 2024-04-27 18:22:31
合計ジャッジ時間 8,752 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
52,924 KB
testcase_01 AC 106 ms
53,960 KB
testcase_02 AC 124 ms
54,020 KB
testcase_03 AC 104 ms
52,924 KB
testcase_04 AC 116 ms
52,956 KB
testcase_05 AC 116 ms
53,852 KB
testcase_06 AC 124 ms
54,180 KB
testcase_07 AC 127 ms
53,988 KB
testcase_08 AC 135 ms
54,060 KB
testcase_09 AC 127 ms
53,940 KB
testcase_10 AC 139 ms
54,080 KB
testcase_11 AC 139 ms
54,356 KB
testcase_12 AC 147 ms
53,796 KB
testcase_13 AC 161 ms
54,252 KB
testcase_14 AC 146 ms
54,308 KB
testcase_15 AC 168 ms
54,356 KB
testcase_16 AC 156 ms
54,200 KB
testcase_17 AC 165 ms
54,552 KB
testcase_18 AC 177 ms
55,080 KB
testcase_19 AC 184 ms
54,260 KB
testcase_20 AC 177 ms
54,468 KB
testcase_21 AC 185 ms
54,484 KB
testcase_22 AC 188 ms
54,624 KB
testcase_23 AC 197 ms
54,464 KB
testcase_24 AC 198 ms
54,624 KB
testcase_25 AC 203 ms
54,724 KB
testcase_26 AC 198 ms
54,636 KB
testcase_27 AC 196 ms
53,712 KB
testcase_28 AC 211 ms
54,584 KB
testcase_29 AC 232 ms
59,408 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