結果

問題 No.2412 YOU Grow Bigger!
ユーザー hari64hari64
提出日時 2023-07-19 22:30:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,239 bytes
コンパイル時間 3,143 ms
コンパイル使用メモリ 215,880 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-20 02:18:09
合計ジャッジ時間 4,110 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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;
            if (grid[h][w]) {
                if (h + 1 < H - 2 && grid[h + 1][w]) dp[h + 1][w] = true;
                if (w + 1 < W - 2 && grid[h][w + 1]) dp[h][w + 1] = 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;
}
0