結果
問題 |
No.1398 調和の魔法陣 (構築)
|
ユーザー |
|
提出日時 | 2021-02-19 22:58:02 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,450 bytes |
コンパイル時間 | 819 ms |
コンパイル使用メモリ | 96,228 KB |
実行使用メモリ | 13,888 KB |
最終ジャッジ日時 | 2024-09-16 21:43:05 |
合計ジャッジ時間 | 10,329 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 TLE * 1 -- * 24 |
ソースコード
#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; } }