結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-11-10 14:01:25 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 487 ms / 3,000 ms |
| コード長 | 765 bytes |
| コンパイル時間 | 1,901 ms |
| コンパイル使用メモリ | 174,004 KB |
| 実行使用メモリ | 121,300 KB |
| 最終ジャッジ日時 | 2024-11-10 14:01:32 |
| 合計ジャッジ時間 | 5,492 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
char s[3005][3005];
int dist[3005][3005];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;++i)scanf("%s",s[i]+1);
memset(dist,63,sizeof(dist));
queue<pair<int,int>>q;
for(int i=0;i<=n+1;++i)for(int j=0;j<=m+1;++j){
if(i==0||i==n+1||j==0||j==m+1){
dist[i][j]=0;q.emplace(i,j);
}else if(s[i][j]!='#'){
dist[i][j]=0;q.emplace(i,j);
}
}
int ans=0;
while(q.size()){
auto au=q.front();q.pop();
int x=au.first,y=au.second;
ans=max(ans,dist[x][y]);
for(int i=-1;i<=1;++i)for(int j=-1;j<=1;++j){
int dx=x+i,dy=y+j;
if(dx<1||dx>n||dy<1||dy>m)continue;
if(dist[dx][dy]>dist[x][y]+1){
dist[dx][dy]=dist[x][y]+1;
q.emplace(dx,dy);
}
}
}
printf("%d\n",ans);
return 0;
}
vjudge1