結果
| 問題 |
No.1398 調和の魔法陣 (構築)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-19 22:52:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,466 bytes |
| コンパイル時間 | 802 ms |
| コンパイル使用メモリ | 95,628 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-16 21:33:08 |
| 合計ジャッジ時間 | 58,012 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 TLE * 4 |
ソースコード
#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++) {
for (int l = 0; l < 10; l++) {
if (i + j + k + l == x) {
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;
}
}
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;
}
}