結果
| 問題 | No.2412 YOU Grow Bigger! | 
| コンテスト | |
| ユーザー |  emthrm | 
| 提出日時 | 2023-08-11 21:54:23 | 
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 201 ms / 6,000 ms | 
| コード長 | 2,030 bytes | 
| コンパイル時間 | 3,061 ms | 
| コンパイル使用メモリ | 260,100 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-21 08:42:47 | 
| 合計ジャッジ時間 | 5,419 ms | 
| ジャッジサーバーID (参考情報) | judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 29 | 
ソースコード
#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;
}
            
            
            
        