結果

問題 No.2412 YOU Grow Bigger!
ユーザー i_am_noobi_am_noob
提出日時 2023-08-11 22:06:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 181 ms / 6,000 ms
コード長 1,513 bytes
コンパイル時間 1,907 ms
コンパイル使用メモリ 209,736 KB
実行使用メモリ 7,784 KB
最終ジャッジ日時 2024-05-01 06:35:51
合計ジャッジ時間 3,901 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 181 ms
6,944 KB
testcase_04 AC 181 ms
7,656 KB
testcase_05 AC 146 ms
7,492 KB
testcase_06 AC 157 ms
6,940 KB
testcase_07 AC 180 ms
6,940 KB
testcase_08 AC 157 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 5 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 7 ms
6,944 KB
testcase_14 AC 3 ms
6,944 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 21 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 4 ms
6,940 KB
testcase_22 AC 7 ms
6,944 KB
testcase_23 AC 37 ms
7,656 KB
testcase_24 AC 72 ms
7,484 KB
testcase_25 AC 37 ms
6,940 KB
testcase_26 AC 4 ms
6,940 KB
testcase_27 AC 3 ms
6,940 KB
testcase_28 AC 10 ms
6,940 KB
testcase_29 AC 2 ms
7,784 KB
testcase_30 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;

#define all(a) a.begin(),a.end()
#define pb push_back
#define sz(a) ((int)a.size())

const int N=2405;
int n,m,b[N][N];
string a[N];
bool vis[N][N];

bool valid(int i, int j){return i>=0&&i<n&&j>=0&&j<m;}

bool bfs(){
    for(int i=0; i<n; ++i) for(int j=0; j<m; ++j) vis[i][j]=0;
    queue<pii> q;
    q.push({1,1}),vis[1][1]=1;
    while(!q.empty()){
        auto [x,y]=q.front(); q.pop();
        for(int i: {-1,0,1}) for(int j: {-1,0,1}){
            int nx=x+i,ny=y+j;
            if(valid(nx,ny)&&b[nx][ny]==0&&!vis[nx][ny]){
                q.push({nx,ny}),vis[nx][ny]=1;
            }
        }
    }
    return vis[n-2][m-2];
}

signed main(){
    ios_base::sync_with_stdio(0),cin.tie(0);
    cin >> n >> m;
    for(int i=0; i<n; ++i) cin >> a[i];
    for(int i=0; i<n; ++i) for(int j=0; j<m; ++j) if(a[i][j]=='#'){
        for(int x: {-1,0,1}) for(int y: {-1,0,1}) if(valid(i+x,j+y)) b[i+x][j+y]++;
    }
    for(int i=0; i<n; ++i) for(int j=0; j<m; ++j) if(i==0||i==n-1||j==0||j==m-1) b[i][j]++;
    if(!bfs()){
        cout << "0\n";
        return 0;
    }
    for(int i=0; i<n; ++i) for(int j=0; j<m; ++j){
        for(int x: {-1,0,1}) for(int y: {-1,0,1}) if(valid(i+x,j+y)) b[i+x][j+y]++;
        if(b[1][1]==0&&b[n-2][m-2]==0&&!bfs()){
            cout << "1\n";
            return 0;
        }
        for(int x: {-1,0,1}) for(int y: {-1,0,1}) if(valid(i+x,j+y)) b[i+x][j+y]--;
    }
    cout << "2\n";
}
0