結果

問題 No.401 数字の渦巻き
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-17 13:53:58
言語 Java21
(openjdk 21)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 948 bytes
コンパイル時間 3,611 ms
コンパイル使用メモリ 76,176 KB
実行使用メモリ 63,680 KB
最終ジャッジ日時 2023-09-06 17:44:12
合計ジャッジ時間 10,385 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
56,236 KB
testcase_01 AC 123 ms
56,844 KB
testcase_02 AC 124 ms
56,224 KB
testcase_03 AC 125 ms
55,904 KB
testcase_04 AC 132 ms
55,840 KB
testcase_05 AC 139 ms
56,100 KB
testcase_06 AC 147 ms
55,988 KB
testcase_07 AC 152 ms
56,036 KB
testcase_08 AC 152 ms
56,032 KB
testcase_09 AC 148 ms
56,164 KB
testcase_10 AC 162 ms
56,192 KB
testcase_11 AC 164 ms
55,696 KB
testcase_12 AC 159 ms
56,612 KB
testcase_13 AC 163 ms
55,972 KB
testcase_14 AC 167 ms
56,060 KB
testcase_15 AC 183 ms
53,840 KB
testcase_16 AC 182 ms
57,992 KB
testcase_17 AC 174 ms
56,352 KB
testcase_18 AC 177 ms
56,648 KB
testcase_19 AC 184 ms
56,716 KB
testcase_20 AC 198 ms
56,164 KB
testcase_21 AC 192 ms
54,232 KB
testcase_22 AC 206 ms
56,440 KB
testcase_23 AC 211 ms
56,128 KB
testcase_24 AC 221 ms
56,996 KB
testcase_25 AC 221 ms
56,332 KB
testcase_26 AC 222 ms
56,716 KB
testcase_27 AC 221 ms
56,688 KB
testcase_28 AC 227 ms
56,728 KB
testcase_29 AC 264 ms
63,680 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class No401 {
	static Scanner sc = new Scanner(System.in);
	static int N = sc.nextInt();
	static int masu[][] = new int[N][N];
	
	public static void main(String[] args) {
		
		masu[0][0] = 1;
		int x = 0,y = 0;
		int houkou = 0; //0:→ 1:↓ 2:← 3:↑
		for(int i = 2;i <= N*N;i++) {
			
			switch(houkou) {
			case 0:
				y++;
				if(y == N-1 || masu[x][y+1] != 0) {
					houkou = (houkou + 1) % 4;
				}
				break;
			case 1:
				x++;
				if(x == N-1 || masu[x+1][y] != 0) {
					houkou = (houkou + 1) % 4;
				}
				break;
			case 2:
				y--;
				if(y == 0 || masu[x][y-1] != 0) {
					houkou = (houkou + 1) % 4;
				}
				break;
			case 3:
				x--;
				if(masu[x-1][y] != 0) {
					houkou = (houkou + 1) % 4;
				}
			}
			masu[x][y] = i;
		}
		
		for(int i = 0;i < N;i++) {
			for(int j = 0;j < N;j++) {
				System.out.printf(String.format("%03d", masu[i][j]) + " ");
			}
			System.out.println();
		}
	}
}
0