結果

問題 No.2412 YOU Grow Bigger!
ユーザー 👑 emthrmemthrm
提出日時 2023-08-11 21:54:23
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 196 ms / 6,000 ms
コード長 2,030 bytes
コンパイル時間 3,319 ms
コンパイル使用メモリ 259,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-01 06:35:09
合計ジャッジ時間 4,838 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,812 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 185 ms
6,940 KB
testcase_04 AC 196 ms
6,940 KB
testcase_05 AC 128 ms
6,944 KB
testcase_06 AC 194 ms
6,944 KB
testcase_07 AC 184 ms
6,944 KB
testcase_08 AC 181 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 6 ms
6,940 KB
testcase_11 AC 1 ms
6,944 KB
testcase_12 AC 1 ms
6,944 KB
testcase_13 AC 10 ms
6,940 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 AC 27 ms
6,944 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 5 ms
6,944 KB
testcase_22 AC 8 ms
6,940 KB
testcase_23 AC 50 ms
6,940 KB
testcase_24 AC 92 ms
6,940 KB
testcase_25 AC 49 ms
6,940 KB
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 3 ms
6,944 KB
testcase_28 AC 14 ms
6,944 KB
testcase_29 AC 2 ms
6,944 KB
testcase_30 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int 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() {
  constexpr int L = 3;
  int h, w; cin >> h >> w;
  vector<string> s(h); REP(i, h) cin >> s[i];
  const auto can_reach = [&]() -> bool {
    static vector is_visited(h - L + 1, vector(w - L + 1, 0));
    REP(i, h - L + 1) ranges::fill(is_visited[i], false);
    is_visited[0][0] = true;
    for (queue<pair<int, int>> que({{0, 0}}); !que.empty(); que.pop()) {
      const auto [i, j] = que.front();
      REP(k, 8) {
        const int y = i + DY8[k], x = j + DX8[k];
        if (0 <= y && y + L - 1 < h && 0 <= x && x + L - 1 < w && !is_visited[y][x]) {
          bool is_valid = true;
          REP(r, L) REP(c, L) is_valid &= s[y + r][x + c] == '.';
          if (is_valid) {
            is_visited[y][x] = true;
            que.emplace(y, x);
          }
        }
      }
    }
    return is_visited[h - L][w - L];
  };
  if (!can_reach()) {
    cout << 0 << '\n';
    return 0;
  }
  REP(i, h) REP(j, w) {
    if ((i < L && j < L) || (i >= h - L && j >= w - L) || s[i][j] == '#') continue;
    s[i][j] = '#';
    if (!can_reach()) {
      cout << 1 << '\n';
      return 0;
    }
    s[i][j] = '.';
  }
  cout << 2 << '\n';
  return 0;
}
0