結果

問題 No.401 数字の渦巻き
ユーザー ieneko18ieneko18
提出日時 2016-11-17 15:44:38
言語 Java21
(openjdk 21)
結果
AC  
実行時間 229 ms / 2,000 ms
コード長 657 bytes
コンパイル時間 1,906 ms
コンパイル使用メモリ 77,556 KB
実行使用メモリ 46,892 KB
最終ジャッジ日時 2024-05-04 14:43:51
合計ジャッジ時間 7,523 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 104 ms
41,404 KB
testcase_01 AC 99 ms
39,948 KB
testcase_02 AC 102 ms
40,344 KB
testcase_03 AC 114 ms
40,832 KB
testcase_04 AC 103 ms
40,148 KB
testcase_05 AC 115 ms
41,404 KB
testcase_06 AC 120 ms
41,104 KB
testcase_07 AC 123 ms
41,216 KB
testcase_08 AC 123 ms
41,300 KB
testcase_09 AC 135 ms
41,608 KB
testcase_10 AC 132 ms
41,336 KB
testcase_11 AC 149 ms
41,812 KB
testcase_12 AC 141 ms
41,168 KB
testcase_13 AC 161 ms
41,604 KB
testcase_14 AC 152 ms
41,716 KB
testcase_15 AC 167 ms
41,584 KB
testcase_16 AC 157 ms
41,900 KB
testcase_17 AC 167 ms
41,792 KB
testcase_18 AC 169 ms
42,000 KB
testcase_19 AC 172 ms
41,864 KB
testcase_20 AC 175 ms
42,004 KB
testcase_21 AC 205 ms
42,492 KB
testcase_22 AC 194 ms
42,348 KB
testcase_23 AC 201 ms
42,124 KB
testcase_24 AC 189 ms
42,420 KB
testcase_25 AC 203 ms
42,736 KB
testcase_26 AC 212 ms
42,436 KB
testcase_27 AC 207 ms
42,592 KB
testcase_28 AC 200 ms
41,776 KB
testcase_29 AC 229 ms
46,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int board[][]=new int[n][n];
		board[0][0]=1;
		int move[][]={{1,0},{0,1},{-1,0},{0,-1}};
		int nx=0;
		int ny=0;
		int d=0;
		for(int i=2;i<=n*n;i++){
			int nnx=nx+move[d][0];
			int nny=ny+move[d][1];
			if(nnx<0||nnx>=n||nny<0||nny>=n){
				d=(d+1)%4;
			}else if(board[nnx][nny]!=0){
				d=(d+1)%4;
			}
			nx+=move[d][0];
			ny+=move[d][1];
			board[nx][ny]=i;
		}
		
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				System.out.printf("%03d ",board[j][i]);
			}
			System.out.println();
		}
	}
}
0