結果

問題 No.1398 調和の魔法陣 (構築)
ユーザー tkmst201
提出日時 2021-02-22 13:34:17
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 93 ms / 3,153 ms
コード長 1,943 bytes
コンパイル時間 2,231 ms
コンパイル使用メモリ 202,176 KB
最終ジャッジ日時 2025-01-19 03:26:39
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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;
};
auto solve = [&](vector<vector<int>> v, vector<vector<int>> & ans) {
REP(i, H) REP(j, W) {
int s = 0;
FOR(dx, -1, 2) FOR(dy, -1, 2) {
const int y = i + dy, x = j + dx;
if (x < 0 || x >= W || y < 0 || y >= H) continue;
s += v[y][x];
}
if (s != X) return;
}
ans = v;
};
vector<vector<int>> ans;
if (X <= 9) {
solve(func(X, 0, 0, 0), ans);
solve(func(0, X, 0, 0), ans);
solve(func(0, 0, X, 0), ans);
solve(func(0, 0, 0, X), ans);
}
if (X <= 18) {
int a, b;
if (X >= 9) a = 9, b = X - 9;
else a = X, b = 0;
solve(func(a, b, 0, 0), ans);
solve(func(a, 0, b, 0), ans);
solve(func(0, 0, a, b), ans);
solve(func(0, a, 0, b), ans);
}
if (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;
}
}
solve(func(x[0][0], x[0][1], x[1][0], x[1][1]), ans);
}
if (ans.empty()) puts("-1");
else {
REP(i, H) {
REP(j, W) printf("%d", ans[i][j]);
puts("");
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0