結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
oxyshower
|
| 提出日時 | 2019-07-11 12:24:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,314 bytes |
| コンパイル時間 | 2,264 ms |
| コンパイル使用メモリ | 172,588 KB |
| 実行使用メモリ | 818,180 KB |
| 最終ジャッジ日時 | 2024-11-07 12:14:11 |
| 合計ジャッジ時間 | 10,221 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 5 MLE * 1 -- * 3 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
char table[3003][3003];
int mp[3003][3003];
queue<pair<int,int>> q;
const int INF = 1 << 30;
signed main(){
int h,w; cin >> h >> w;
for(int i = 0; i <= h+1; i++){
for(int j = 0; j <= w+1; j++){
if(i == 0 || j == 0 || i == h+1 || j == w+1){
q.push({i,j});
table[i][j] = 0;
continue;
}
char c; cin >> c;
table[i][j] = c;
if(table[i][j] == '.'){
q.push({i,j});
mp[i][j] = 0;
}
else mp[i][j] = INF;
}
}
while(!q.empty()){
auto p = q.front(); q.pop();
for(int dx : {-1,0,1}){
for(int dy : {-1,0,1}){
int ny = p.first + dy;
int nx = p.second + dx;
if(ny < 0 || h+1 < ny || nx < 0 || h+1 < nx) continue;
if(mp[ny][nx] == INF) q.push({ny,nx});
if((ny == 1 || ny == h || nx == 1 || nx == w) && table[ny][nx] == '#') mp[ny][nx] = 1;
if(1 <= ny && ny <= h && 1 <= nx && nx <= w) mp[p.first][p.second] = min(mp[p.first][p.second],mp[ny][nx]+1);
}
}
}
int ans = 0;
for(int i = 0; i <= h; i++){
for(int j = 0; j <= w; j++){
ans = max(ans,mp[i][j]);
}
}
cout << ans << endl;
return 0;
}
//bfs snippets
oxyshower