結果
| 問題 | No.2412 YOU Grow Bigger! | 
| コンテスト | |
| ユーザー |  milanis48663220 | 
| 提出日時 | 2023-08-12 00:03:50 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 347 ms / 6,000 ms | 
| コード長 | 3,201 bytes | 
| コンパイル時間 | 1,221 ms | 
| コンパイル使用メモリ | 126,120 KB | 
| 最終ジャッジ日時 | 2025-02-16 02:29:30 | 
| ジャッジサーバーID (参考情報) | judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 29 | 
ソースコード
#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, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, 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 < 8; 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;
}
            
            
            
        