結果

問題 No.401 数字の渦巻き
ユーザー masamasa
提出日時 2016-07-22 22:39:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 763 bytes
コンパイル時間 690 ms
コンパイル使用メモリ 76,656 KB
実行使用メモリ 13,888 KB
最終ジャッジ日時 2024-04-24 02:23:17
合計ジャッジ時間 3,993 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};

int main() {
	int n;

	cin >> n;
	vector<vector<int>> a(n, vector<int>(n, -1));
	int x = 0;
	int y = 0;
	int dir = 0;
	int nx, ny;

	int z = 1;
	while (z <= n*n) {
		while (0 <= x && x < n && 0 <= y && y < n && a[y][x] == -1) {
			a[y][x] = z;
			x = (x + dx[dir]) % 4;
			y = (y + dy[dir]) % 4;
			z++;
		}
		x = (x + 4 - dx[dir]) % 4;
		y = (y + 4 - dy[dir]) % 4;
		dir = (dir + 1) % 4;
		x = (x + dx[dir]) % 4;
		y = (y + dy[dir]) % 4;
	}

	for (auto aa : a) {
		for (auto aaa : aa) {
			printf("%03d ", aaa);
		}
		printf("\n");
	}
	return 0;
}
0