結果

問題 No.401 数字の渦巻き
ユーザー nCk_cvnCk_cv
提出日時 2016-08-28 19:15:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 255 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 56,592 KB
最終ジャッジ日時 2024-11-14 06:27:46
合計ジャッジ時間 8,837 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
54,060 KB
testcase_01 AC 136 ms
54,196 KB
testcase_02 AC 127 ms
54,016 KB
testcase_03 AC 133 ms
54,000 KB
testcase_04 AC 135 ms
54,472 KB
testcase_05 AC 134 ms
53,880 KB
testcase_06 AC 140 ms
54,256 KB
testcase_07 AC 146 ms
54,104 KB
testcase_08 AC 154 ms
54,776 KB
testcase_09 AC 158 ms
54,408 KB
testcase_10 AC 162 ms
54,684 KB
testcase_11 AC 160 ms
54,324 KB
testcase_12 AC 160 ms
54,300 KB
testcase_13 AC 165 ms
54,124 KB
testcase_14 AC 183 ms
55,068 KB
testcase_15 AC 175 ms
54,472 KB
testcase_16 AC 193 ms
54,744 KB
testcase_17 AC 191 ms
54,396 KB
testcase_18 AC 197 ms
54,340 KB
testcase_19 AC 205 ms
54,596 KB
testcase_20 AC 206 ms
54,780 KB
testcase_21 AC 209 ms
54,596 KB
testcase_22 AC 212 ms
54,656 KB
testcase_23 AC 212 ms
54,500 KB
testcase_24 AC 204 ms
54,384 KB
testcase_25 AC 218 ms
56,592 KB
testcase_26 AC 225 ms
54,696 KB
testcase_27 AC 216 ms
54,700 KB
testcase_28 AC 224 ms
54,576 KB
testcase_29 AC 255 ms
55,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main {
		static int INF = 2 << 27;
		public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			int[][] map = new int[N][N];
			int x = 0;
			int y = 0;
			int v = 0;
			int[] vx = {1,0,-1,0};
			int[] vy = {0,1,0,-1};
			for(int i = 1; i <= N * N; i++) {
				map[y][x] = i;
				int tx = x + vx[v];
				int ty = y + vy[v];
				if(ty < 0 || tx < 0 || ty >= map.length || tx >= map[ty].length || map[ty][tx] != 0) v = (v + 1) % 4;
				x = x + vx[v];
				y = y + vy[v];
				
			}
			for(int i = 0; i < N; i++) {
				System.out.printf("%03d", map[i][0]);
				for(int j = 1; j < N; j++) {
					System.out.printf(" %03d", map[i][j]);
				}
				System.out.println();
			}
			
		}
		

}
0