結果

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

ソースコード

diff #
プレゼンテーションモードにする

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
constexpr int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
IOSetup() {
std::cin.tie(nullptr);
std::ios_base::sync_with_stdio(false);
std::cout << fixed << setprecision(20);
}
} iosetup;
int main() {
int w, h, x; cin >> w >> h >> x;
vector m(h, vector(w, 0));
if (x <= 9) {
vector<int> r, c;
if (h % 3 == 0) {
for (int i = 1; i < h; i += 3) r.emplace_back(i);
} else if (h % 3 == 1) {
r.emplace_back(0);
for (int i = 3; i < h; i += 3) r.emplace_back(i);
r.emplace_back(h - 1);
} else {
for (int i = 0; i < h; i += 3) r.emplace_back(i);
}
if (w % 3 == 0) {
for (int j = 1; j < w; j += 3) c.emplace_back(j);
} else if (w % 3 == 1) {
c.emplace_back(0);
for (int j = 3; j < w; j += 3) c.emplace_back(j);
c.emplace_back(w - 1);
} else {
for (int j = 0; j < w; j += 3) c.emplace_back(j);
}
for (int i : r) for (int j : c) m[i][j] = x;
} else if (x <= 18) {
if (h % 3 == 2) {
for (int j = (w % 3 == 0 ? 1 : 0); j < w; j += 3) for (int i = 0; i + 1 < h; i += 3) {
m[i][j] = 9;
m[i + 1][j] = x - 9;
}
} else if (w % 3 == 2) {
for (int i = (h % 3 == 0 ? 1 : 0); i < h; i += 3) for (int j = 0; j + 1 < w; j += 3) {
m[i][j] = 9;
m[i][j + 1] = x - 9;
}
} else {
cout << "-1\n";
return 0;
}
} else if (x <= 36) {
if (h % 3 != 2 || w % 3 != 2) {
cout << "-1\n";
return 0;
}
for (int i = 0; i + 1 < h; i += 3) for (int j = 0; j + 1 < w; j += 3) {
m[i][j] = m[i][j + 1] = 9;
m[i + 1][j] = min(x - 18, 9);
m[i + 1][j + 1] = x - (m[i + 1][j] + 18);
}
} else {
cout << "-1\n";
return 0;
}
REP(i, h) {
REP(j, w) cout << m[i][j];
cout << '\n';
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0