結果

問題 No.1434 Make Maze
ユーザー 👑 emthrmemthrm
提出日時 2021-03-19 22:27:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,676 bytes
コンパイル時間 2,330 ms
コンパイル使用メモリ 210,528 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 17:32:30
合計ジャッジ時間 6,051 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 WA -
testcase_11 AC 2 ms
5,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 RE -
testcase_30 RE -
testcase_31 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0