結果
| 問題 | No.402 最も海から遠い場所 |
| コンテスト | |
| ユーザー |
tossy
|
| 提出日時 | 2016-07-22 22:55:05 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,579 bytes |
| 記録 | |
| コンパイル時間 | 1,173 ms |
| コンパイル使用メモリ | 96,528 KB |
| 実行使用メモリ | 147,396 KB |
| 最終ジャッジ日時 | 2024-11-06 12:55:30 |
| 合計ジャッジ時間 | 4,735 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 WA * 5 |
ソースコード
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define INF 1<<30
typedef pair<int, pair<int, int> > P;
int mat[3005][3005];
int main(){
int h,w;
cin>>h>>w;
fill(mat[0], mat[3005], INF);
queue<P> que;
char c[3005];
rep(i,h){
scanf("%s", c);
rep(j,w){
if(c[j]=='.'){
mat[i][j] = 0;
que.push(mp(0,mp(i,j)));
}
}
}
// insert out of map
rep(i,h+2){ que.push(mp(0,mp(-1, i-1))); que.push(mp(0,mp(w, i-1)));}
rep(i,w ){ que.push(mp(0,mp(i, -1))); que.push(mp(0,mp(i, h)));}
int res=0;
while(!que.empty()){
const int di[] = {-1,1,0}, dj[]={0,-1,1};
P p = que.front(); que.pop();
int nl = p.first+1;
int i = p.second.first, j = p.second.second;
rep(ri, 3) rep(rj,3){
int ni = i+di[ri], nj = j+dj[rj];
if(ni<0 || ni>=h || nj<0 || nj>=w) continue;
if(mat[ni][nj] > nl){
mat[ni][nj] = nl;
que.push(mp(nl, mp(ni,nj)));
res = max(res, nl);
}
}
}
cout<<res<<endl;
return 0;
}
tossy