結果

問題 No.401 数字の渦巻き
ユーザー nCk_cvnCk_cv
提出日時 2016-08-28 19:15:59
言語 Java21
(openjdk 21)
結果
AC  
実行時間 259 ms / 2,000 ms
コード長 768 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 77,232 KB
実行使用メモリ 48,296 KB
最終ジャッジ日時 2024-04-26 17:02:14
合計ジャッジ時間 9,190 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
41,404 KB
testcase_01 AC 115 ms
40,300 KB
testcase_02 AC 124 ms
39,976 KB
testcase_03 AC 131 ms
41,336 KB
testcase_04 AC 136 ms
41,180 KB
testcase_05 AC 134 ms
41,192 KB
testcase_06 AC 128 ms
40,452 KB
testcase_07 AC 146 ms
41,372 KB
testcase_08 AC 148 ms
41,652 KB
testcase_09 AC 153 ms
42,028 KB
testcase_10 AC 152 ms
41,476 KB
testcase_11 AC 162 ms
41,856 KB
testcase_12 AC 165 ms
41,976 KB
testcase_13 AC 172 ms
41,476 KB
testcase_14 AC 174 ms
41,640 KB
testcase_15 AC 189 ms
41,712 KB
testcase_16 AC 176 ms
41,800 KB
testcase_17 AC 180 ms
41,632 KB
testcase_18 AC 194 ms
41,716 KB
testcase_19 AC 212 ms
41,888 KB
testcase_20 AC 199 ms
41,500 KB
testcase_21 AC 211 ms
42,428 KB
testcase_22 AC 214 ms
42,168 KB
testcase_23 AC 218 ms
42,312 KB
testcase_24 AC 222 ms
42,168 KB
testcase_25 AC 232 ms
42,180 KB
testcase_26 AC 225 ms
42,292 KB
testcase_27 AC 227 ms
42,608 KB
testcase_28 AC 237 ms
42,604 KB
testcase_29 AC 259 ms
48,296 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