結果

問題 No.401 数字の渦巻き
ユーザー aaaaaa
提出日時 2018-10-29 21:22:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,007 bytes
コンパイル時間 1,049 ms
コンパイル使用メモリ 104,620 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-12 08:49:59
合計ジャッジ時間 2,308 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>

using namespace std;

int main(){
	int i, j;
	int n;
	vector<vector<bool>>flag(55, vector<bool>(55, false));
	vector<vector<int>>matrix(55, vector<int>(55, 0));
	int x = 0, y = 0, num = 1;

	cin >> n;

	if (n == 1) {
		cout << "001" << endl;
		return 0;
	}
	else if (n == 2) {
		cout << "001" << " " << "002" << endl;
		cout << "004" << " " << "003" << endl;
		return 0;
	}
	

	while (true) {
		bool flag2 = false;


		for (i = 0; i < n; i++) {
			if (flag[y][x] == true) {
				break;
			}
			else {
				matrix[y][x] = num;
				flag[y][x] = true;
				x++;
				num++;
				flag2 = true;
			}
		}

		x--;
		y++;

		for (i = 0; i < n - 1; i++) {
			if (flag[y][x] == true) {
				break;
			}
			else {
				matrix[y][x] = num;
				flag[y][x] = true;
				y++;
				num++;
				flag2 = true;
			}
		}

		y--;
		x--;

		for (i = 0; i < n - 1; i++) {
			if (flag[y][x] == true || x < 0) {
				break;
			}
			else {
				matrix[y][x] = num;
				flag[y][x] = true;
				x--;
				num++;
				flag2 = true;
			}
		}

		x++;
		y--;

		for (i = 0; i < n - 1; i++) {
			if (flag[y][x] == true) {
				break;
			}
			else {
				matrix[y][x] = num;
				flag[y][x] = true;
				y--;
				num++;
				flag2 = true;
			}
		}

		x++;
		y++;

		if (flag2 == false) {
			break;
		}


	/*	for (i = 0; i < n; i++) {
			for (j = 0; j < n; j++) {
				cout << setw(3) << setfill('0') << matrix[i][j];
				if (j != n - 1) {
					cout << " ";
				}
			}
			cout << endl;
		}
		cout << endl;*/

	}


	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			cout << setw(3) << setfill('0') << matrix[i][j];
			if (j != n - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}









	getchar();
	getchar();
	return 0;
}
0