結果
| 問題 |
No.402 最も海から遠い場所
|
| ユーザー |
|
| 提出日時 | 2016-07-23 00:06:09 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,571 bytes |
| コンパイル時間 | 1,140 ms |
| コンパイル使用メモリ | 89,992 KB |
| 実行使用メモリ | 158,924 KB |
| 最終ジャッジ日時 | 2024-11-06 13:42:44 |
| 合計ジャッジ時間 | 5,725 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 10 WA * 9 |
ソースコード
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>
#include <tuple>
using namespace std;
typedef tuple<int, int, int> TUP;
const vector<int> dx = {1, 1, 0, -1, -1, -1, 0, 1};
const vector<int> dy = {0, 1, 1, 1, 0, -1, -1, -1};
const int INF = 1e9;
void show(vector<vector<int>> &v) {
cout <<"---------" << endl;
for (auto vv : v) {
for (auto vvv : vv) {
if (vvv == INF) {
printf("INF ");
} else {
printf("%3d ", vvv);
}
}
printf("\n");
}
}
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
for (int i = 0; i < h; i++) {
cin >> s[i];
}
vector<vector<int>> t(h, vector<int>(w,INF));
queue<TUP> que;
for (int i = 0; i < h; i++) {
que.push(make_tuple(i, -1, 0));
que.push(make_tuple(i, w, 0));
}
for (int i = 0; i < w; i++) {
que.push(make_tuple(-1, i, 0));
que.push(make_tuple( h, i, 0));
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
if (s[i][j] == '.') {
que.push(make_tuple(i, j, 0));
t[i][j] = 0;
}
}
}
int ans = 0;
while (!que.empty()) {
auto tup = que.front();
que.pop();
int x = get<0>(tup);
int y = get<1>(tup);
int v = get<2>(tup);
int nv = v + 1;
for (int i = 0; i < 8; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || w <= nx || ny < 0 || h <= ny) {
continue;
}
if (nv < t[ny][nx]) {
t[ny][nx] = nv;
que.push(make_tuple(nx, ny, nv));
ans = max(ans, nv);
}
}
}
// show(t);
cout << ans << endl;
return 0;
}