結果
| 問題 |
No.2412 YOU Grow Bigger!
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-08-11 21:57:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,146 bytes |
| コンパイル時間 | 1,119 ms |
| コンパイル使用メモリ | 83,968 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-18 16:12:15 |
| 合計ジャッジ時間 | 2,493 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 27 WA * 2 |
ソースコード
#include<iostream>
#include<algorithm>
#include<queue>
#include<cassert>
using namespace std;
int H,W;
vector<string>S;
vector<vector<int> >vis;
const int d[5]={0,1,0,-1};
bool f()
{
for(int i=1;i<H-1;i++)for(int j=1;j<W-1;j++)
{
bool out=false;
for(int x=i-1;x<=i+1;x++)for(int y=j-1;y<=j+1;y++)
{
if(S[x][y]=='#')out=true;
}
vis[i][j]=out?0:1;
}
queue<pair<int,int> >Q;
Q.push(make_pair(1,1));
vis[1][1]=2;
while(!Q.empty())
{
int x=Q.front().first,y=Q.front().second;
Q.pop();
for(int r=0;r<4;r++)
{
int tx=x+d[r],ty=y+d[r+1];
if(vis[tx][ty]!=1)continue;
vis[tx][ty]=2;
Q.push(make_pair(tx,ty));
}
}
return vis[H-2][W-2]!=2;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin>>H>>W;
S=vector<string>(H);
vis=vector<vector<int> >(H,vector<int>(W,0));
for(int i=0;i<H;i++)cin>>S[i];
if(f())cout<<0<<endl;
else
{
bool fn=false;
for(int i=0;!fn&&i<H;i++)for(int j=0;j<W;j++)
{
if(i<3&&j<3)continue;
if(H-i<=3&&W-j<=3)continue;
if(S[i][j]=='#')continue;
S[i][j]='#';
if(f())
{
fn=true;
break;
}
S[i][j]='.';
}
cout<<(fn?1:2)<<endl;
}
}