結果

問題 No.401 数字の渦巻き
ユーザー LogicR_pimanLogicR_piman
提出日時 2016-09-26 03:29:30
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,188 bytes
コンパイル時間 487 ms
コンパイル使用メモリ 57,300 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 21:10:45
合計ジャッジ時間 1,756 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 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<iostream>
#include<string>

using namespace std;

/*void replace(string *s, int i, int x, int y) {
	int d, e ;
	string ii;
	ii = to_string(i);
	d = i / 10 + 1;
	e = y * (n * 4 + 1) + x * 4;
	s.replace(e, d, i);
}*/

int main() {
	int n, nn, i, j, k, x = 0, y = 0, d=0, e=0, f=0;
	string s, ii;

	cin >> n;

	nn = n*n;

	for (i = 0; i < n-1; i++) {
		for (j = 0; j < n * 4; j++) {
			s.insert(0, "0");
		}
		s.insert(0, "\n");
	}
	for (j = 0; j < n * 4; j++) {
		s.insert(0, "0");
	}

	//cout << s << endl;

	
	for (i = 1; i <= 3 * n - 2; i++) {


		if (i == 1) {
			x = 0;
			y = 0;
		}
		else if (i <= n) {
			x += 1;
			y = 0;
		}
		else if (i <= 2 * n - 1) {
			y += 1;
		}
		else if (i <= 3 * n - 2) {
			x -= 1;
		}

		if (i <= 3 * n - 2) {
			if (i < 10) d = 2;
			else if (i < 100) d = 3;
			else d = 4;
			e = y * (n * 4 + 1) + x * 4 - d + 4;
			ii = to_string(i);
			ii += " ";
			s.replace(e, d, ii);
		}
		
	}
	while(1){
		if (i > 3 * n - 2) {
			for (k = 0; k < n - 2 - f; k++) {
				y -= 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i);
				ii += " ";
				//cout << i << x << y << endl;
				s.replace(e, d, ii);
				i++;
			}
			if (i > nn) break;
			for (k = 0; k < n - 2 - f; k++) {
				x += 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i);
				ii += " ";
				//cout << i << x << y << endl;
				s.replace(e, d, ii);
				i++;
			}
			if (i > nn) break;
			for (k = 0; k < n - 3 - f; k++) {
				y += 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i);
				ii += " ";
				//cout << i << x << y << endl;
				s.replace(e, d, ii);
				i++;
			}
			if (i > nn) break;
			for (k = 0; k < n - 3 - f; k++) {
				x -= 1;
				if (i < 10) d = 2;
				else if (i < 100) d = 3;
				else d = 4;
				e = y * (n * 4 + 1) + x * 4 - d + 4;
				ii = to_string(i);
				ii += " ";
				//cout << i << x << y << endl;
				s.replace(e, d, ii);
				i++;
			}
			if (i > nn) break;
			f += 2;
		}
	}


	cout << s << endl;


	return 0;


}
0