結果

問題 No.401 数字の渦巻き
ユーザー kotamanegikotamanegi
提出日時 2016-07-22 22:46:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,288 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 85,600 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-24 02:25:25
合計ジャッジ時間 1,388 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <iomanip>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(int i = 0;i < n;++i)
int hoge[100][100] = {};
int main() {
	int n;
	cin >> n;
	pair<int, int> now_here = make_pair(1,1);
	hoge[1][1] = 1;
	for (int i = 0;i < n;++i) {
		hoge[0][i+1] = 99999;
		hoge[i+1][0] = 99999;
		hoge[i+1][n+1] = 99999;
		hoge[n+1][i+1] = 99999;
	}
	int going = 0;
	while (true) {
		if (going == 0) {
			if (hoge[now_here.first + 1][now_here.second] == 0) {
				hoge[now_here.first + 1][now_here.second] = hoge[now_here.first][now_here.second] + 1;
				now_here.first++;
			}
			else {
				if (hoge[now_here.first][now_here.second+1] == 0) {
					going = 1;
				}
				else goto endout;
			}
		}else if (going == 1) {
			if (hoge[now_here.first][now_here.second + 1] == 0) {
				hoge[now_here.first][now_here.second + 1] = hoge[now_here.first][now_here.second] + 1;
				now_here.second++;
			}
			else {
				if (hoge[now_here.first - 1][now_here.second] == 0) {
					going = 2;
				}
				else goto endout;
	}
		}else if (going == 2) {
			if (hoge[now_here.first - 1][now_here.second] == 0) {
				hoge[now_here.first - 1][now_here.second] = hoge[now_here.first][now_here.second] + 1;
				now_here.first--;
			}
			else {
				if (hoge[now_here.first][now_here.second - 1] == 0) {
					going = 3;
				}
				else goto endout;
	}
		}		else if (going == 3) {
			if (hoge[now_here.first][now_here.second - 1] == 0) {
				hoge[now_here.first][now_here.second - 1] = hoge[now_here.first][now_here.second] + 1;
				now_here.second--;
			}
			else {
				if (hoge[now_here.first + 1][now_here.second] == 0) {
					going = 0;
				}
				else goto endout;
			}
		}
	}
endout:;
	for (int i = 1;i <= n;++i) {
		for (int q = 1;q <= n;++q) {
			if (hoge[q][i] < 100) {
				cout << "0";
			}
			if (hoge[q][i] < 10) {
				cout << "0";
			}
			cout << hoge[q][i] << " ";
		}
		cout << endl;
	}
	return 0;
}
0