結果
問題 | No.1434 Make Maze |
ユーザー |
![]() |
提出日時 | 2021-06-06 10:26:01 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,185 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 204,448 KB |
最終ジャッジ日時 | 2025-01-22 03:53:41 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 WA * 1 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define REP(i,n) FOR(i,0,n)#define ALL(v) begin(v),end(v)template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }using ll = long long;using pii = pair<int, int>;constexpr ll INF = 1ll<<30;constexpr ll longINF = 1ll<<60;constexpr ll MOD = 1000000007;constexpr bool debug = false;//---------------------------------///*** @brief https://tkmst201.github.io/Library/DataStructure/UnionFind.hpp*/struct UnionFind {using size_type = std::size_t;private:size_type n;std::vector<int> dat;public:explicit UnionFind(size_type n) : n(n), dat(n, -1) {}size_type size(size_type x) noexcept {assert(x < n);return -dat[find(x)];}size_type find(size_type x) noexcept {assert(x < n);if (dat[x] < 0) return x;return dat[x] = find(dat[x]);}void unite(size_type x, size_type y) noexcept {assert(x < n);assert(y < n);x = find(x);y = find(y);if (x == y) return;if (dat[x] < dat[y]) std::swap(x, y);dat[y] += dat[x];dat[x] = y;}bool issame(size_type x, size_type y) noexcept {assert(x < n);assert(y < n);return find(x) == find(y);}};int main() {int H, W, X;cin >> H >> W >> X;int h = (H + 1) / 2, w = (W + 1) / 2;if (X % 2 == 1 || (h + w) % 2 != X / 2 % 2) { puts("-1"); return 0; }X /= 2;bool trans = false;if (h % 2 == 0) {trans = true;swap(H, W);swap(h, w);}constexpr int dx[] {-1,0,1,0}, dy[] {0,-1,0,1}; // lurd ^1 で転置vector<int> dirs;// (h, w) = (odd, even) or (even, even)if (h + w - 2 > X || h * w - 1 < X || ((~(h | w) & 1) && h * w - 1 == X)) { puts("-1"); return 0; }X -= h + w - 2;REP(i, (h - 1) / 2) {// rrr d lll dconst int cur = min(X / 2, w - 1);REP(j, cur) dirs.emplace_back(2);dirs.emplace_back(3);REP(j, cur) dirs.emplace_back(0);dirs.emplace_back(3);X -= cur * 2;}if (h & 1) REP(i, w - 1) dirs.emplace_back(2); // relse {REP(i, X / 2) {dirs.emplace_back(3); // ddirs.emplace_back(2); // rdirs.emplace_back(1); // u}REP(i, w - 1 - X / 2) dirs.emplace_back(2); // rdirs.emplace_back(3); // d}if (trans) {for (int & a : dirs) a ^= 1;swap(H, W);swap(h, w);}vector<string> ans(H, string(W, '#'));REP(i, h) REP(j, w) ans[i << 1][j << 1] = '.';vector done(H, vector<int>(W));done[0][0] = true;int y = 0, x = 0;for (int dir : dirs) {const int ny = y + dy[dir], nx = x + dx[dir];ans[ny][nx] = '.';done[ny][nx] = true;y += 2 * dy[dir];x += 2 * dx[dir];done[y][x] = true;}REP(i, H) REP(j, W) {REP(dir, 4) {int ny = i + 2 * dy[dir], nx = j + 2 * dx[dir];if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;if (ans[i][j] == '#' || ans[ny][nx] == '#') continue;if (done[ny][nx]) continue;done[ny][nx] = true;done[i + dy[dir]][j + dx[dir]] = true;ans[i + dy[dir]][j + dx[dir]] = '.';}}REP(i, H) cout << ans[i] << '\n';}