結果
| 問題 |
No.2412 YOU Grow Bigger!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-19 22:35:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,482 bytes |
| コンパイル時間 | 2,786 ms |
| コンパイル使用メモリ | 211,436 KB |
| 最終ジャッジ日時 | 2025-02-15 15:48:16 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 25 WA * 4 |
ソースコード
#ifndef hari64
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define debug(...)
#else
#include "util/viewer.hpp"
#define debug(...) viewer::_debug(__LINE__, #__VA_ARGS__, __VA_ARGS__)
#endif
// clang-format off
using namespace std;
using ll = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<ll, ll>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vc<T>>;
template <typename T> using vvvc = vector<vvc<T>>;
using vi = vc<int>; using vll = vc<ll>; using vpii = vc<pii>; using vpll = vc<pll>;
using vvi = vc<vi>; using vvll = vc<vll>; using vvpi = vc<vpii>; using vvpll = vc<vpll>;
#define ALL(x) begin(x), end(x)
#define RALL(x) (x).rbegin(), (x).rend()
constexpr int INF = 1001001001; constexpr long long INFll = 1001001001001001001;
template <class T> bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template <class T> bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
// clang-format on
int H, W;
vector<string> Ss;
bool canReach() {
vector<vector<bool>> grid(H - 2, vector<bool>(W - 2, INF));
for (int h = 1; h < H - 1; h++) {
for (int w = 1; w < W - 1; w++) {
grid[h - 1][w - 1] = true;
for (int dh = -1; dh <= 1; dh++) {
for (int dw = -1; dw <= 1; dw++) {
if (Ss[h + dh][w + dw] == '#') {
grid[h - 1][w - 1] = false;
}
}
}
}
}
assert(grid[0][0] == true && grid[H - 3][W - 3] == true);
// 0,0からH-3,W-3までの経路があるか
vector<vector<bool>> dp(H - 2, vector<bool>(W - 2, false));
dp[0][0] = true;
for (int h = 0; h < H - 2; h++) {
for (int w = 0; w < W - 2; w++) {
if (!dp[h][w]) continue;
for (int dh = -1; dh <= 1; dh++) {
for (int dw = -1; dw <= 1; dw++) {
if (dh == 0 && dw == 0) continue;
if (h + dh < 0 || h + dh >= H - 2) continue;
if (w + dw < 0 || w + dw >= W - 2) continue;
if (grid[h + dh][w + dw]) {
dp[h + dh][w + dw] = true;
}
}
}
}
}
return dp[H - 3][W - 3];
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
cin >> H >> W;
assert(6 <= H && 6 <= W);
assert(H * W <= 2400);
Ss.resize(H);
for (auto& S : Ss) {
cin >> S;
assert(int(S.size()) == W);
for (auto& c : S) {
assert(c == '.' || c == '#');
}
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
assert(Ss[i][j] == '.');
}
}
for (int i = H - 3; i < H; i++) {
for (int j = W - 3; j < W; j++) {
assert(Ss[i][j] == '.');
}
}
int ans = 2;
if (!canReach()) {
ans = 0;
} else {
for (int h = 0; h < H && ans == 2; h++) {
for (int w = 0; w < W && ans == 2; w++) {
if (h < 3 && w < 3) continue;
if (h >= H - 3 && w >= W - 3) continue;
if (Ss[h][w] == '#') continue;
Ss[h][w] = '#';
if (!canReach()) {
ans = 1;
}
Ss[h][w] = '.';
}
}
}
cout << ans << endl;
return 0;
}