結果

問題 No.1434 Make Maze
ユーザー 👑 emthrmemthrm
提出日時 2021-03-19 23:02:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 3,879 bytes
コンパイル時間 2,619 ms
コンパイル使用メモリ 214,140 KB
実行使用メモリ 21,780 KB
最終ジャッジ日時 2023-08-16 09:25:59
合計ジャッジ時間 8,151 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 34 ms
21,764 KB
testcase_03 AC 34 ms
21,780 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,388 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,384 KB
testcase_15 AC 10 ms
8,296 KB
testcase_16 AC 4 ms
4,788 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 5 ms
5,500 KB
testcase_19 AC 20 ms
12,788 KB
testcase_20 AC 4 ms
4,872 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 8 ms
7,168 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 14 ms
10,148 KB
testcase_25 AC 22 ms
15,200 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 30 ms
14,656 KB
testcase_28 AC 3 ms
4,492 KB
testcase_29 AC 3 ms
4,380 KB
testcase_30 AC 10 ms
7,708 KB
testcase_31 AC 5 ms
5,432 KB
権限があれば一括ダウンロードができます

ソースコード

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, vector(4, false)));
  auto solve = [&]() -> void {
    for (int i = 0; i < r; i += 2) {
      REP(j, c - 1) dir[i][j][3] = true;
      dir[i][c - 1][0] = true;
    }
    for (int i = 1; i < r; i += 2) {
      dir[i][0][0] = true;
      FOR(j, 1, c) dir[i][j][1] = true;
    }
    fill(ALL(dir[r - 1][c - 1]), false);
    int cur = r * c - 1;
    for (int i = r - 2; i >= 0; i -= 2) {
      REP(j, c - 1) {
        if (cur > x) {
          dir[i][j][0] = false;
          dir[i + 1][j][3] = false;
          dir[i][j + 1][0] = true;
          dir[i + 1][j + 1][1] = true;
          cur -= 2;
        }
      }
    }
  };
  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, vector(4, false)));
    solve();
    swap(r, c);
    vector nx(r, vector(c, vector(4, false)));
    REP(i, r) REP(j, c) REP(k, 4) nx[i][j][3 - k] = dir[j][i][k];
    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] = true;
      dir[i][c - 1][0] = true;
    }
    for (int i = 1; i < r - 2; i += 2) {
      dir[i][0][0] = true;
      FOR(j, 1, c) dir[i][j][1] = true;
    }
    dir[r - 2][0][3] = true;
    for (int j = 1; j < c; j += 2) {
      dir[r - 2][j][0] = true;
      dir[r - 1][j][3] = true;
    }
    for (int j = 2; j < c; j += 2) {
      dir[r - 2][j][3] = true;
      dir[r - 1][j][2] = true;
    }
    fill(ALL(dir[r - 1][c - 1]), false);
    dir[r - 2][0][0] = true;
    int cur = r * c - 2;
    for (int j = 2; j < c; j += 2) {
      if (cur > x) {
        dir[r - 2][j - 1][3] = true;
        dir[r - 1][j - 1][3] = false;
        dir[r - 2][j][3] = true;
        dir[r - 1][j][1] = false;
        cur -= 2;
      }
    }
    for (int i = r - 3; i >= 0; i -= 2) {
      REP(j, c - 1) {
        if (cur > x) {
          dir[i + 1][j][3] = false;
          dir[i][j + 1][0] = true;
          cur -= 2;
        }
      }
    }
  }
  // REP(k, 4) {
  //   REP(i, r) REP(j, c) cout << dir[i][j][k] << " \n"[j + 1 == c];
  //   cout << '\n';
  // }
  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) REP(k, 4) {
    if (dir[i][j][k]) ans[i * 2 + dy[k]][j * 2 + dx[k]] = '.';
  }
  REP(i, h) REP(j, w) {
    if (i % 2 == 0 && j % 2 == 0) assert(ans[i][j] == '.');
    if (i % 2 == 1 && j % 2 == 1) assert(ans[i][j] == '#');
  }
  REP(i, h) cout << ans[i] << '\n';
  return 0;
}
0