結果

問題 No.401 数字の渦巻き
ユーザー fjafjafjafjafjafja
提出日時 2017-09-11 01:41:25
言語 Java19
(openjdk 21)
結果
AC  
実行時間 195 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 77,596 KB
実行使用メモリ 56,700 KB
最終ジャッジ日時 2023-08-07 09:12:24
合計ジャッジ時間 9,581 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,268 KB
testcase_01 AC 119 ms
55,684 KB
testcase_02 AC 121 ms
56,296 KB
testcase_03 AC 123 ms
56,216 KB
testcase_04 AC 123 ms
56,188 KB
testcase_05 AC 126 ms
56,208 KB
testcase_06 AC 128 ms
56,328 KB
testcase_07 AC 130 ms
55,964 KB
testcase_08 AC 133 ms
56,356 KB
testcase_09 AC 140 ms
56,536 KB
testcase_10 AC 141 ms
55,916 KB
testcase_11 AC 146 ms
56,472 KB
testcase_12 AC 146 ms
56,564 KB
testcase_13 AC 149 ms
56,176 KB
testcase_14 AC 157 ms
56,676 KB
testcase_15 AC 163 ms
56,456 KB
testcase_16 AC 168 ms
56,468 KB
testcase_17 AC 170 ms
56,488 KB
testcase_18 AC 167 ms
56,004 KB
testcase_19 AC 170 ms
55,860 KB
testcase_20 AC 181 ms
55,704 KB
testcase_21 AC 171 ms
56,012 KB
testcase_22 AC 173 ms
56,312 KB
testcase_23 AC 177 ms
56,492 KB
testcase_24 AC 186 ms
55,948 KB
testcase_25 AC 188 ms
56,480 KB
testcase_26 AC 179 ms
56,700 KB
testcase_27 AC 190 ms
55,992 KB
testcase_28 AC 195 ms
56,324 KB
testcase_29 AC 195 ms
56,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Scanner;

public class N401
{

	public static void main(String[] args)
	{
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int drc=0;
		int now=1;
		int i=0,j=0;
		int[][] h=new int[N][N];

		for(int k=0;k<N;k++)
			for(int l=0;l<N;l++)
			{
				h[k][l]=0;
			}
		h[0][0]=1;

		while(now!=N*N)
		{
			switch (drc%4)
			{
				case 0:
					while(j+1<N&&h[i][j+1]==0)
					{
						h[i][++j]=++now;
						//System.out.println("h["+i+"]["+j+"]="+now);
					}
					drc++;
					break;
				case 1:
					while(i+1<N&&h[i+1][j]==0)
					{
						h[++i][j]=++now;
						//System.out.println("h["+i+"]["+j+"]="+now);
					}
					drc++;
					break;
				case 2:
					while(0<=j-1&&h[i][j-1]==0)
					{
						h[i][--j]=++now;
						//System.out.println("h["+i+"]["+j+"]="+now);
					}
					drc++;
					break;
				case 3:
					while(0<=i-1&&h[i-1][j]==0)
					{
						h[--i][j]=++now;
						//System.out.println("h["+i+"]["+j+"]="+now);
					}
					drc++;
					break;

			}
		}


		for(int ii=0;ii<N;ii++)
		{
			for(int jj=0;jj<N;jj++)
			{
				if(h[ii][jj]<=9)
				{
					System.out.printf("00%d",h[ii][jj]);
				}
				else if(10<=h[ii][jj]&&h[ii][jj]<=99)
				{
					System.out.printf("0%d",h[ii][jj]);
				}
				else if(100<=h[ii][jj])
				{
					System.out.printf("%d",h[ii][jj]);
				}

				if(jj==N-1){System.out.println();}
				else{System.out.print(" ");}
			}
		}


	}

}
0