結果

問題 No.2412 YOU Grow Bigger!
ユーザー milanis48663220milanis48663220
提出日時 2023-08-11 23:59:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,173 bytes
コンパイル時間 1,386 ms
コンパイル使用メモリ 130,440 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 15:15:39
合計ジャッジ時間 3,524 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 205 ms
5,376 KB
testcase_04 AC 213 ms
5,376 KB
testcase_05 AC 140 ms
5,376 KB
testcase_06 AC 183 ms
5,376 KB
testcase_07 AC 206 ms
5,376 KB
testcase_08 AC 158 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 5 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 8 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 22 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 WA -
testcase_22 AC 7 ms
5,376 KB
testcase_23 AC 25 ms
5,376 KB
testcase_24 AC 89 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 5 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 11 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/maxflow>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using P = pair<int, int>;
using T = tuple<int, int, int>;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int h, w; cin >> h >> w;
    vector<string> s(h);
    for(int i = 0; i < h; i++) cin >> s[i];
    auto ok = [&](int i, int j){
        for(int x = 0; x < 3; x++){
            for(int y = 0; y < 3; y++){
                if(s[i+x][j+y] == '#') return false;        
            }
        }
        return true;
    };
    
    auto move_ok = [&](){
        auto f = vec2d(h-2, w-2, true);
        for(int i = 0; i < h-2; i++){
            for(int j = 0; j < w-2; j++){
                f[i][j] = ok(i, j);
            }
        }
        auto in_field = [&](int x, int y){
            return 0 <= x && x < h-2 && 0 <= y && y < w-2;
        };
        auto dp = vec2d(h-2, w-2, false);
        queue<P> que;
        auto set_dp = [&](int x, int y){
            if(!dp[x][y]){
                dp[x][y] = true;
                que.push({x, y});
            }
        };
        set_dp(0, 0);
        while(!que.empty()){
            auto [x, y] = que.front(); que.pop();
            for(int k = 0; k < 4; k++){
                int xx = x+dx[k];
                int yy = y+dy[k];
                if(!in_field(xx, yy)) continue;
                if(!f[xx][yy]) continue;
                set_dp(xx, yy);
            }
        }
        if(dp[h-3][w-3]) return true;
        return false;
    };
    if(!move_ok()){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i <= 2 && j <= 2) continue;
            if(i >= h-3 && j >= w-3) continue;
            if(s[i][j] == '#') continue;
            s[i][j] = '#';
            if(!move_ok()){
                cout << 1 << endl;
                return 0;
            }
            s[i][j] = '.';
        }
    }
    cout << 2 << endl;
}
0