結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー 夜
提出日時 2021-02-19 22:52:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,466 bytes
コンパイル時間 951 ms
コンパイル使用メモリ 94,748 KB
実行使用メモリ 5,228 KB
最終ジャッジ日時 2023-10-15 04:02:11
合計ジャッジ時間 12,827 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,372 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 1 ms
4,352 KB
testcase_06 AC 522 ms
5,068 KB
testcase_07 TLE -
testcase_08 AC 197 ms
4,884 KB
testcase_09 AC 2,993 ms
4,956 KB
testcase_10 AC 2,668 ms
4,896 KB
testcase_11 AC 227 ms
4,972 KB
testcase_12 TLE -
testcase_13 AC 70 ms
5,016 KB
testcase_14 AC 3,019 ms
5,092 KB
testcase_15 AC 2,854 ms
4,880 KB
testcase_16 AC 33 ms
5,180 KB
testcase_17 AC 30 ms
5,104 KB
testcase_18 AC 30 ms
4,900 KB
testcase_19 AC 30 ms
5,040 KB
testcase_20 AC 2 ms
4,372 KB
testcase_21 AC 33 ms
4,968 KB
testcase_22 AC 293 ms
4,960 KB
testcase_23 AC 2,593 ms
5,040 KB
testcase_24 AC 71 ms
4,952 KB
testcase_25 TLE -
testcase_26 AC 31 ms
5,020 KB
testcase_27 AC 29 ms
5,040 KB
testcase_28 AC 2,709 ms
5,036 KB
testcase_29 AC 32 ms
5,228 KB
testcase_30 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int m[660][660];
int b1[10] = { 0,0,0,1,1,1,-1,-1,-1 };
int b2[10] = { 0,1,-1,0,1,-1,0,1,-1 };
int main() {
	int w, h, x;
	cin >> w >> h >> x;
	if (x == 0) {
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cout << 0;
			}
			cout << endl;
		}
		return 0;
	}
	if (h == 1 && w == 1) {
		if (x > 9) {
			cout << -1 << endl;
		}
		else {
			cout << x << endl;
		}
	}
	else if (h == 1) {
		if (x > 18) {
			cout << -1 << endl;
		}
		else {
			for (int i = 0; i < w; i++) {
				if (i % 3 == 0) {
					cout << x / 9 * 9;
				}
				else if (i % 3 == 1) {
					cout << x % 9;
				}
				else {
					cout << 0;
				}
			}
			cout << endl;
		}
	}
	else if (w == 1) {
		if (x > 18) {
			cout << -1 << endl;
		}
		else {
			for (int i = 0; i < h; i++) {
				if (i % 3 == 0) {
					cout << x / 9 * 9 << endl;
				}
				else if (i % 3 == 1) {
					cout << x % 9 << endl;
				}
				else {
					cout << 0 << endl;
				}
			}
		}
	}
	else {
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				for (int k = 0; k < 10; k++) {
					for (int l = 0; l < 10; l++) {
						if (i + j + k + l == x) {
							for (int a = 0; a < h; a++) {
								for (int b = 0; b < w; b++) {
									if (a % 3 == 0 && b % 3 == 0) {
										m[a][b] = i;
									}
									else if (a % 3 == 1 && b % 3 == 0) {
										m[a][b] = j;
									}
									else if (a % 3 == 0 && b % 3 == 1) {
										m[a][b] = k;
									}
									else if (a % 3 == 1 && b % 3 == 1) {
										m[a][b] = l;
									}
									else {
										m[a][b] = 0;
									}
								}
							}
							bool bo = true;
							for (int a = 0; a < h; a++) {
								for (int b = 0; b < w; b++) {
									int co = 0;
									for (int c = 0; c < 9; c++) {
										if (a + b1[c] < 0 || a + b1[c] >= h || b + b2[c] < 0 || b + b2[c] >= w)continue;
										else co += m[a + b1[c]][b + b2[c]];
									}
									if (co != x)bo = false;
								}
							}
							if (bo) {
								for (int a = 0; a < h; a++) {
									for (int b = 0; b < w; b++) {
										cout << m[a][b];
									}
									cout << endl;
								}
								return 0;
							}
						}
					}
				}
			}
		}
		cout << -1 << endl;
	}
}
0