結果

問題 No.401 数字の渦巻き
ユーザー hanorver
提出日時 2016-07-22 22:58:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 689 bytes
コンパイル時間 632 ms
コンパイル使用メモリ 76,652 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-06 09:14:13
合計ジャッジ時間 1,567 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>

int main() {
	int n;

	std::cin >> n;

	std::vector<int> v(n * n, 0);
	std::vector<int> dirct = {1, n, -1, -n};
	int p = 1, pos = n - 1, count = n + 1;
	double move_cost = n - 0.5;

	v[0] = 1;

	for (int i = 0; i < n; i++) {
		v[i] = i + 1;
	}

	while (floor(move_cost) != 0) {
		for (int i = 0; i < floor(move_cost); i++) {
			v[pos + dirct[p]] = count;
			count++;
			pos += dirct[p];
		}
		p = (p + 1) % 4;
		move_cost -= 0.5;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			printf("%03d", v[i * n + j]);
			if (j != n - 1) printf(" ");
		}
		printf("\n");
	}
	
	return 0;
}
0