結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2018-03-06 21:23:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 322 ms / 3,000 ms |
| コード長 | 1,283 bytes |
| コンパイル時間 | 839 ms |
| コンパイル使用メモリ | 88,048 KB |
| 実行使用メモリ | 57,684 KB |
| 最終ジャッジ日時 | 2024-09-21 20:02:36 |
| 合計ジャッジ時間 | 4,727 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int h, w;
cin >> h >> w;
queue<pair<int16_t, int16_t>> q;
for (int i = 2; i < h + 2; i++) {
q.push({ i, 1 });
q.push({ i, w + 2 });
}
for (int j = 2; j < w + 2; j++) {
q.push({ 1, j });
q.push({ h + 2, j });
}
vector<vector<int16_t>> a(h + 4, vector<int16_t>(w + 4, 0));
string s;
for (int i = 0; i < h; i++) {
cin >> s;
for (int j = 0; j < w; j++) {
if (s[j] == '#') {
a[i + 2][j + 2] = 1 << 14;
} else {
q.push({ i + 2, j + 2 });
}
}
}
int r = 0;
while (!q.empty()) {
auto p = q.front(); q.pop();
int d = a[p.first][p.second] + 1;
for (int i = p.first - 1; i <= p.first + 1; i++) {
for (int j = p.second - 1; j <= p.second + 1; j++) {
if (a[i][j] > d) {
r = a[i][j] = d;
q.push({ i, j });
}
}
}
}
cout << r << endl;
return 0;
}
merom686