結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2016-07-27 15:46:07 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 497 ms / 3,000 ms |
コード長 | 1,216 bytes |
コンパイル時間 | 1,991 ms |
コンパイル使用メモリ | 182,684 KB |
実行使用メモリ | 121,360 KB |
最終ジャッジ日時 | 2024-11-06 17:57:28 |
合計ジャッジ時間 | 5,291 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include<bits/stdc++.h> using namespace std; struct I{ I(){ ios::sync_with_stdio(false); cin.tie(0); } }cww; typedef vector<string> VS; typedef vector<int> VI; typedef vector<VI> VVI; VS wrap(VS v,char c){ int R=v.size(); int C=v[0].size(); VS res(R+2,string(C+2,c)); for(int i=1;i<=R;i++) for(int j=1;j<=C;j++) res[i][j]=v[i-1][j-1]; return res; } const int dir8[]={0,1,-1,1,1,0,-1,-1,0}; int main(){ int R,C,res=0; cin>>R>>C; VS m(R); for(auto &it:m)cin>>it; m=wrap(wrap(m,'.'),'W'); VVI d(R=m.size(),VI(C=m[0].size(),0)); using P=tuple<int,int>; queue<P> que; for(int i=0;i<R;i++) for(int j=0;j<C;j++) if(m[i][j]=='.') que.push(P(i,j)); else if(m[i][j]=='#') d[i][j]=-1; while(que.size()){ int r,c; tie(r,c)=que.front();que.pop(); res=max(res,d[r][c]); for(int i=0;i<8;i++){ int nr=r+dir8[i]; int nc=c+dir8[i+1]; if(d[nr][nc]==-1){ d[nr][nc]=d[r][c]+1; que.push(P(nr,nc)); } } } cout<<res<<endl; return 0; }