結果
問題 | No.1398 調和の魔法陣 (構築) |
ユーザー |
![]() |
提出日時 | 2021-02-20 09:44:18 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,901 ms / 3,153 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 2,151 ms |
コンパイル使用メモリ | 100,624 KB |
最終ジャッジ日時 | 2025-01-19 02:35:33 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include <cassert> #include <vector> #include <iostream> using namespace std; int main() { int w, h, x; cin >> w >> h >> x; int a[3][3] = {{0, 0, 0},{0, 0, 0},{0, 0, 0}}; int s = 0; for (int i = 0; i < 2; i++) { if (h % 3 == i) continue; for (int j = 0; j < 2; j++) { if (w % 3 == j) continue; a[i][j] = min(9, x-s); s += a[i][j]; } } if (s != x) cout << -1 << endl; else { vector ans(h, vector<int>(w, 0)); for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) ans[i][j] = a[i%3][j%3]; for (int i = 0; i < h; i++) { for (int a : ans[i]) cout << a; cout << endl; } for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) { int sum = 0; for (int x = i-1; x <= i+1; x++) for (int y = j-1; y <= j+1; y++) if (0 <= x && x < h && 0 <= y && y < w) sum += ans[x][y]; cerr << i << ' ' << j << ' ' << sum << endl; assert(sum == x); } } }