結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー tkmst201tkmst201
提出日時 2021-02-22 11:29:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,830 bytes
コンパイル時間 2,712 ms
コンパイル使用メモリ 209,552 KB
実行使用メモリ 6,200 KB
最終ジャッジ日時 2023-10-21 09:43:41
合計ジャッジ時間 32,643 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int W, H, X;
	cin >> W >> H >> X;
	
	auto func = [&](int lu, int ru, int ld, int rd) {
		int x[2][2] = {{lu, ru}, {ld, rd}};
		vector res(H, vector<int>(W));
		REP(i, H) REP(j, W) if (i % 3 != 2 && j % 3 != 2) res[i][j] = x[i % 3][j % 3];
		return res;
	};
	
	vector<vector<int>> ans;
	if (X == 0) ans.assign(H, vector(W, 0));
	if (X <= 9) {
		if (H % 3 == 0 && W % 3 == 0) ans = func(0, 0, 0, X);
		else if (H == 1 && W == 1) ans = func(X, 0, 0, 0);
	}
	if ((H >= 2 || W >= 2) && X <= 18) {
		int a, b;
		if (X >= 9) a = 9, b = X - 9;
		else a = X, b = 0;
		
		if (H % 3 != 0 || W % 3 != 0) {
			if (W >= 2 && H % 3 == 0) ans = func(0, 0, a, b);
			else if (H >= 2 && W % 3 == 0) ans = func(0, a, 0, b);
			else if (H >= 2) ans = func(a, 0, b, 0);
			else ans = func(a, b, 0, 0);
		}
	}
	if (H >= 2 && W >= 2 && X <= 36) {
		int x[2][2] {};
		REP(i, 10) REP(j, 10) REP(k, 10) {
			int s = i + j + k;
			if (s <= X && X - s <= 9) {
				x[0][0] = i;
				x[0][1] = j;
				x[1][0] = k;
				x[1][1] = X - s;
			}
		}
		if (H % 3 != 0 && W % 3 != 0) ans = func(x[0][0], x[0][1], x[1][0], x[1][1]);
	}
	
	if (ans.empty()) puts("-1");
	else {
		REP(i, H) {
			REP(j, W) printf("%d", ans[i][j]);
			puts("");
		}
	}
}
0