結果
| 問題 |
No.402 最も海から遠い場所
|
| ユーザー |
femto
|
| 提出日時 | 2016-07-22 23:06:03 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,073 bytes |
| コンパイル時間 | 727 ms |
| コンパイル使用メモリ | 73,696 KB |
| 実行使用メモリ | 121,740 KB |
| 最終ジャッジ日時 | 2024-11-06 12:59:12 |
| 合計ジャッジ時間 | 4,993 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 RE * 4 |
ソースコード
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
using namespace std;
const int INF = 1000000;
char b[3000][3000];
int d[3000][3000];
int dx[8] = { 0, 1, 1, 1, 0, -1, -1, -1 }, dy[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
struct P {
int x, y;
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int H, W;
cin >> H >> W;
fill((int*)begin(d), (int*)end(d), INF);
queue<P> q;
for(int i = 0; i < H + 2; i++) {
for(int j = 0; j < W + 2; j++) {
if(i != 0 && i != H + 1 && j != 0 && j != W + 1) {
cin >> b[i][j];
}
else {
b[i][j] = '.';
}
if(b[i][j] == '.') {
d[i][j] = 0;
q.push(P{ j, i });
}
}
}
int ans = 0;
while(!q.empty()) {
P p = q.front();
q.pop();
for(int i = 0; i < 8; i++) {
int ny = p.y + dy[i], nx = p.x + dx[i];
if(0 <= nx && nx <= W && 0 <= ny && ny <= H && d[p.y][p.x] + 1 < d[ny][nx]) {
d[ny][nx] = d[p.y][p.x] + 1;
q.push(P{ nx, ny });
ans = max(ans, d[ny][nx]);
}
}
}
cout << ans << endl;
}
femto