結果

問題 No.401 数字の渦巻き
ユーザー fjafjafjafjafjafja
提出日時 2017-09-11 01:41:25
言語 Java21
(openjdk 21)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 1,414 bytes
コンパイル時間 4,188 ms
コンパイル使用メモリ 77,312 KB
実行使用メモリ 42,312 KB
最終ジャッジ日時 2024-04-25 03:16:20
合計ジャッジ時間 10,850 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
41,364 KB
testcase_01 AC 144 ms
41,276 KB
testcase_02 AC 143 ms
41,264 KB
testcase_03 AC 146 ms
41,316 KB
testcase_04 AC 152 ms
41,740 KB
testcase_05 AC 152 ms
41,424 KB
testcase_06 AC 151 ms
41,140 KB
testcase_07 AC 152 ms
41,516 KB
testcase_08 AC 155 ms
41,436 KB
testcase_09 AC 169 ms
41,548 KB
testcase_10 AC 170 ms
41,628 KB
testcase_11 AC 175 ms
41,824 KB
testcase_12 AC 167 ms
41,408 KB
testcase_13 AC 185 ms
41,548 KB
testcase_14 AC 175 ms
41,756 KB
testcase_15 AC 184 ms
41,660 KB
testcase_16 AC 195 ms
41,880 KB
testcase_17 AC 190 ms
41,580 KB
testcase_18 AC 190 ms
41,456 KB
testcase_19 AC 192 ms
41,628 KB
testcase_20 AC 199 ms
42,024 KB
testcase_21 AC 208 ms
42,312 KB
testcase_22 AC 206 ms
42,004 KB
testcase_23 AC 213 ms
41,968 KB
testcase_24 AC 199 ms
41,948 KB
testcase_25 AC 214 ms
41,916 KB
testcase_26 AC 214 ms
42,308 KB
testcase_27 AC 203 ms
41,944 KB
testcase_28 AC 208 ms
42,212 KB
testcase_29 AC 206 ms
42,264 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