結果

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

テストケース

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

ソースコード

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++) {
					if (i + j + k >= x - 9) {
						int l = x - i - j - k;
						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;
									break;
								}
							}
						}
						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