結果

問題 No.2412 YOU Grow Bigger!
ユーザー i_am_noobi_am_noob
提出日時 2023-08-11 22:05:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,485 bytes
コンパイル時間 2,279 ms
コンパイル使用メモリ 207,992 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-29 13:03:15
合計ジャッジ時間 3,243 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 6 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 5 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 6 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 3 ms
5,376 KB
testcase_22 AC 5 ms
5,376 KB
testcase_23 AC 3 ms
5,376 KB
testcase_24 AC 5 ms
5,376 KB
testcase_25 WA -
testcase_26 AC 4 ms
5,376 KB
testcase_27 AC 3 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 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(!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