結果

問題 No.401 数字の渦巻き
コンテスト
ユーザー FF256grhy
提出日時 2016-07-22 22:47:58
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 511 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 219 ms
コンパイル使用メモリ 40,192 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-05-06 12:14:16
合計ジャッジ時間 1,560 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h> 

int n, f[30][30];
int dx[4] = {1, 0, -1,  0};
int dy[4] = {0, 1,  0, -1};

int main() {
	scanf("%d", &n);
	
	int x = 0, y = 0, d = 0;
	for(int i = 1; i <= n * n; i++) {
		f[x][y] = i;
		int xx = x + dx[d];
		int yy = y + dy[d];
		if( ! (0 <= xx && xx < n && 0 <= yy && yy < n && f[xx][yy] == 0) ) { d++; d %= 4; }
		x += dx[d];
		y += dy[d];
	}
	
	for(int i = 0; i < n; i++) {
	for(int j = 0; j < n; j++) {
		printf("%s%03d", j == 0 ? "" : " ", f[j][i]);
	} printf("\n");
	}
	
	return 0;
}
0