結果

問題 No.401 数字の渦巻き
ユーザー ぴろずぴろず
提出日時 2016-07-22 22:26:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 237 ms / 2,000 ms
コード長 684 bytes
コンパイル時間 1,794 ms
コンパイル使用メモリ 78,024 KB
実行使用メモリ 48,820 KB
最終ジャッジ日時 2024-04-24 02:15:51
合計ジャッジ時間 7,422 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
40,376 KB
testcase_01 AC 110 ms
41,056 KB
testcase_02 AC 102 ms
40,372 KB
testcase_03 AC 110 ms
40,340 KB
testcase_04 AC 116 ms
40,644 KB
testcase_05 AC 122 ms
41,076 KB
testcase_06 AC 123 ms
41,360 KB
testcase_07 AC 125 ms
41,508 KB
testcase_08 AC 133 ms
41,348 KB
testcase_09 AC 133 ms
41,364 KB
testcase_10 AC 140 ms
41,400 KB
testcase_11 AC 145 ms
41,540 KB
testcase_12 AC 141 ms
41,396 KB
testcase_13 AC 147 ms
41,828 KB
testcase_14 AC 164 ms
41,596 KB
testcase_15 AC 159 ms
41,908 KB
testcase_16 AC 172 ms
42,012 KB
testcase_17 AC 169 ms
41,944 KB
testcase_18 AC 168 ms
41,580 KB
testcase_19 AC 187 ms
42,052 KB
testcase_20 AC 182 ms
42,272 KB
testcase_21 AC 192 ms
41,880 KB
testcase_22 AC 213 ms
42,272 KB
testcase_23 AC 187 ms
42,048 KB
testcase_24 AC 185 ms
41,924 KB
testcase_25 AC 208 ms
42,504 KB
testcase_26 AC 209 ms
42,232 KB
testcase_27 AC 204 ms
42,632 KB
testcase_28 AC 204 ms
42,644 KB
testcase_29 AC 237 ms
48,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no402;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		int di = 0, dj = 1;
		int ci = 0, cj = 0;
		for(int i=1;i<=n*n;i++) {
			a[ci][cj] = i;
			int ni = ci + di;
			int nj = cj + dj;
			if (ni < 0 || ni >= n || nj < 0 || nj >= n || a[ni][nj] != 0) {
				int temp = di;
				di = dj;
				dj = -temp;
			}
			ci = ci + di;
			cj = cj + dj;
		}
		for(int i=0;i<n;i++) {
			for(int j=0;j<n;j++) {
				if (j > 0) {
					System.out.print(' ');
				}
				System.out.print(String.format("%03d", a[i][j]));
			}
			System.out.println();
		}
	}

}
0