結果

問題 No.401 数字の渦巻き
ユーザー masamasa
提出日時 2016-07-22 22:49:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 720 bytes
コンパイル時間 788 ms
コンパイル使用メモリ 74,808 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 06:09:13
合計ジャッジ時間 1,780 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 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,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 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,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:34:20: 警告: ‘y’ may be used uninitialized [-Wmaybe-uninitialized]
   34 |                 ny = (y + dy[dir]);
      |                 ~~~^~~~~~~~~~~~~~~
main.cpp:21:16: 備考: ‘y’ はここで定義されています
   21 |         int x, y;
      |                ^
main.cpp:33:20: 警告: ‘x’ may be used uninitialized [-Wmaybe-uninitialized]
   33 |                 nx = (x + dx[dir]);
      |                 ~~~^~~~~~~~~~~~~~~
main.cpp:21:13: 備考: ‘x’ はここで定義されています
   21 |         int x, y;
      |             ^

ソースコード

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 nx = 0;
	int ny = 0;
	int dir = 0;
	int x, y;
	int z = 1;
	while (z <= n*n) {
		while (0 <= nx && nx < n && 0 <= ny && ny < n && a[ny][nx] == -1) {
			x = nx;
			y = ny;
			a[y][x] = z;
			nx = (x + dx[dir]);
			ny = (y + dy[dir]);
			z++;
		}
		dir = (dir + 1) % 4;
		nx = (x + dx[dir]);
		ny = (y + dy[dir]);
	}

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