結果

問題 No.401 数字の渦巻き
ユーザー moyashi_senpaimoyashi_senpai
提出日時 2016-07-22 22:39:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 74,388 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 02:23:10
合計ジャッジ時間 1,256 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 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 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 1 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:24:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   24 |         scanf("%d", &n);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
using namespace std;

#define Getsign(n) ((n > 0) - (n < 0))

typedef vector<int> Ivec;
typedef pair<int, int> Pos;

const pair<int, int> dira[4] = { {0,1},{1,0},{0,-1},{-1,0} };

int main() {
	int n;
	int m[32][32] = {};
	scanf("%d", &n);

	for (int i = 0; n + 1 > i; i++) {
		m[i][0] = -1;
		m[0][i] = -1;
		m[n + 1][i] = -1;
		m[i][n + 1] = -1;
	}
	Pos pos = { 1 ,1};
	int cou = 1;
	int dir = 0;
	while (1) {

		if (m[pos.first][pos.second] != 0) {
			pos.first -= dira[dir].first;
			pos.second -= dira[dir].second;
			dir = (dir + 1) % 4;
			pos.first += dira[dir].first;
			pos.second += dira[dir].second;
			if (m[pos.first][pos.second]!= 0) {
				break;
			}
			continue;
		}

		m[pos.first][pos.second] = cou;
		pos.first += dira[dir].first;
		pos.second += dira[dir].second;
		cou++;
	}

	for (int i = 1; n + 1 > i; i++) {
		for (int j = 1; n + 1 > j; j++) {
			printf("%03d", m[i][j]);
			if (j != n)printf(" ");
		}
		printf("\n");
	}

	return 0;
}
0