結果

問題 No.401 数字の渦巻き
ユーザー snrnsidysnrnsidy
提出日時 2021-09-12 20:15:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 680 bytes
コンパイル時間 2,953 ms
コンパイル使用メモリ 198,424 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-06 17:26:16
合計ジャッジ時間 4,034 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,388 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int dy[4] = { 0,1,0,-1 };
int dx[4] = { 1,0,-1,0 };
int board[31][31];

int main(void)
{
	int n;
	int num = 1;
	int state = 0;
	int move = 0;
	int max = 1;

	memset(board,-1,sizeof(board));

	scanf("%d",&n);

	int y = 0;
	int x = 0;
	int dir = 0;
	while(num<=n*n)
	{
		board[y][x] = num++;
		int ny = y + dy[dir];
		int nx = x + dx[dir];
		if(ny<0 || ny>=n || nx<0 || nx>=n)
		{
			dir++;
			dir%=4;
		}
		else if(board[ny][nx]!=-1)
		{
			dir++;
			dir%=4;
		}
		y += dy[dir];
		x += dx[dir];
	}

	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			printf("%03d ",board[i][j]);
		}
		printf("\n");
	}

	return 0;
}
0