結果
| 問題 |
No.1434 Make Maze
|
| コンテスト | |
| ユーザー |
emthrm
|
| 提出日時 | 2021-03-19 22:27:17 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,676 bytes |
| コンパイル時間 | 2,172 ms |
| コンパイル使用メモリ | 203,656 KB |
| 最終ジャッジ日時 | 2025-01-19 18:48:27 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 1 |
| other | AC * 9 WA * 19 RE * 2 |
ソースコード
#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 h, w, x; cin >> h >> w >> x;
if (x & 1) {
cout << "-1\n";
return 0;
}
x /= 2;
int r = (h + 1) / 2, c = (w + 1) / 2;
if (x < r - 1 + c - 1) {
cout << "-1\n";
return 0;
}
vector dir(r, vector(c, -1));
auto solve = [&]() -> void {
for (int i = 0; i < r; i += 2) {
REP(j, c - 1) dir[i][j] = 3;
dir[i][c - 1] = 0;
}
for (int i = 1; i < r; i += 2) {
dir[i][0] = 0;
FOR(j, 1, c) dir[i][j] = 1;
}
int cur = r * c - 1;
for (int i = r - 2; i >= 0; i -= 2) {
REP(j, c - 1) {
if (cur > x) {
dir[i][j + 1] = dir[i][j];
dir[i + 1][j + 1] = dir[i + 1][j];
dir[i][j] = dir[i + 1][j] = -1;
cur -= 2;
}
}
}
dir[r - 1][c - 1] = -1;
};
if (r % 2 == 1) {
if (x > r * c - 1 || (r * c - 1 - x) % 2 == 1) {
cout << "-1\n";
return 0;
}
solve();
} else if (c % 2 == 1) {
if (x > r * c - 1 || (r * c - 1 - x) % 2 == 1) {
cout << "-1\n";
return 0;
}
swap(r, c);
dir = vector(r, vector(c, -1));
solve();
swap(r, c);
vector nx(r, vector(c, -1));
REP(i, r) REP(j, c) nx[i][j] = 3 - dir[j][i];
dir.swap(nx);
} else {
if (x > r * c - 2 || (r * c - 2 - x) % 2 == 1) {
cout << "-1\n";
return 0;
}
for (int i = 0; i < r - 2; i += 2) {
REP(j, c - 1) dir[i][j] = 3;
dir[i][c - 1] = 0;
}
for (int i = 1; i < r - 2; i += 2) {
dir[i][0] = 0;
FOR(j, 1, c) dir[i][j] = 1;
}
dir[r - 2][0] = 3;
for (int j = 1; j < c; j += 2) {
dir[r - 2][j] = 0;
dir[r - 1][j] = 3;
}
for (int j = 2; j < c; j += 2) {
dir[r - 2][j] = 3;
dir[r - 1][j] = 2;
}
int cur = r * c - 2;
for (int j = 2; j < c; j += 2) {
if (cur > x) {
dir[r - 2][j - 1] = dir[r - 1][j - 1];
dir[r - 1][j - 1] = dir[r - 1][j] = -1;
cur -= 2;
}
}
for (int i = r - 3; i >= 0; i -= 2) {
REP(j, c - 1) {
if (cur > x) {
dir[i][j + 1] = dir[i][j];
dir[i + 1][j + 1] = dir[i + 1][j];
dir[i][j] = dir[i + 1][j] = -1;
cur -= 2;
}
}
}
dir[r - 1][c - 1] = -1;
}
// REP(i, r) REP(j, c) cout << dir[i][j] << " \n"[j + 1 == c];
vector ans(h, string(w, '#'));
for (int i = 0; i < h; i += 2) for (int j = 0; j < w; j += 2) ans[i][j] = '.';
REP(i, r) REP(j, c) {
if (dir[i][j] == 0) {
ans[i * 2 + 1][j * 2] = '.';
} else if (dir[i][j] == 1) {
ans[i * 2][j * 2 - 1] = '.';
} else if (dir[i][j] == 2) {
ans[i * 2 - 1][j * 2] = '.';
} else if (dir[i][j] == 3) {
ans[i * 2][j * 2 + 1] = '.';
}
}
REP(i, h) cout << ans[i] << '\n';
return 0;
}
emthrm