結果
問題 |
No.157 2つの空洞
|
ユーザー |
![]() |
提出日時 | 2020-08-11 00:11:32 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,531 bytes |
コンパイル時間 | 4,161 ms |
コンパイル使用メモリ | 172,120 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-08 22:36:39 |
合計ジャッジ時間 | 2,658 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; int main(){ int dx[5]={1,-1,0,0},dy[5]={0,0,1,-1}; int w,h,a[30][30],b[30][30],i,j; scanf("%d %d\n",&h,&w); for(i=0;i<=w+1;i++){ for(j=0;j<=h+1;j++){ a[i][j]=2,b[i][j]=(1<<29); } } queue<P> que; for(i=1;i<=w;i++){ for(j=1;j<=h;j++){ char s; scanf("%c",&s); if(s=='.'){ a[i][j]=0; if(que.empty()){ que.push(P(i,j)); b[i][j]=0; } } else{ a[i][j]=1; } } scanf("\n"); } while(!que.empty()){ P p=que.front(); que.pop(); for(i=0;i<4;i++){ if(a[p.first+dx[i]][p.second+dy[i]]==0 && b[p.first+dx[i]][p.second+dy[i]]>b[p.first][p.second]){ b[p.first+dx[i]][p.second+dy[i]]=b[p.first][p.second]; que.push(P(p.first+dx[i],p.second+dy[i])); } if(a[p.first+dx[i]][p.second+dy[i]]==1 && b[p.first+dx[i]][p.second+dy[i]]>b[p.first][p.second]+1){ b[p.first+dx[i]][p.second+dy[i]]=b[p.first][p.second]+1; que.push(P(p.first+dx[i],p.second+dy[i])); } } } for(i=1;i<=w;i++){ for(j=1;j<=h;j++){ if(a[i][j]==0 && b[i][j]!=0){ cout << b[i][j] << endl; return 0; } } } }