結果

問題 No.401 数字の渦巻き
ユーザー KhiromuKhiromu
提出日時 2017-07-09 10:51:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 860 bytes
コンパイル時間 636 ms
コンパイル使用メモリ 66,144 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-29 03:31:44
合計ジャッジ時間 2,266 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<algorithm>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)
#define RREP(i, a, n) for(int i=n-1; i>=a; i--)
#define CH(a, l, r) (l<=a && a<=r)
#define INF 1000000000
#define ll long long

int dy[4] = { 0, 1, 0, -1 };
int dx[4] = { 1, 0, -1, 0 };
int main()
{
	int N;
	cin >> N;

	int field[31][31];
	REP(i, 0, 31) REP(j, 0, 31) field[i][j] = 0;
	
	int cnt = 1;
	int dir = 0;
	int y = 0, x = 0;
	bool flag = true;
	while (flag) {
		flag = false;

		while (CH(y, 0, N - 1) && CH(x, 0, N - 1)) {
			if (field[y][x] != 0) break;
			flag = true;
			field[y][x] = cnt;
			
			cnt++;
			y += dy[dir % 4];
			x += dx[dir % 4];
		}
		y -= dy[dir % 4];
		x -= dx[dir % 4];
		dir++;
		y += dy[dir % 4];
		x += dx[dir % 4];
	}

	REP(i, 0, N){
		REP(j, 0, N) {
			printf("%03d ", field[i][j]);
		}
		printf("\n");
	}
	return 0;
}
0