結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2024-11-08 22:49:26 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 409 ms / 3,000 ms |
| コード長 | 1,291 bytes |
| コンパイル時間 | 1,342 ms |
| コンパイル使用メモリ | 98,940 KB |
| 実行使用メモリ | 103,640 KB |
| 最終ジャッジ日時 | 2024-11-08 22:49:31 |
| 合計ジャッジ時間 | 4,523 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <cstdio>
#include <queue>
#define rep(i, l, r) for (int i = (l); i <= (r); i ++ )
#define per(i, r, l) for (int i = (r); i >= (l); i -- )
using namespace std;
const int N = 3005, dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
int n, m;
string ch[N];
bool st[N][N];
queue<pair<int, int> > q1, q2;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
rep(i, 1, n) {
cin >> ch[i];
ch[i] = '.' + ch[i] + '.';
}
rep(i, 0, m + 1) ch[0] += '.', ch[n + 1] += '.';
rep(i, 0, n + 1) rep(j, 0, m + 1)
if (ch[i][j] == '.') {
q1.push({i, j});
st[i][j] = 1;
}
int now = 0, ans = 0;
while (!q1.empty()) {
swap(q1, q2);
while (!q2.empty()) {
auto t = q2.front(); q2.pop();
rep(dx, -1, 1) rep(dy, -1, 1) if (dx != 0 || dy != 0) {
int nx = t.first + dx, ny = t.second + dy;
ans = max(ans, now);
if (nx < 0 || ny < 0 || nx > n + 1 || ny > m + 1) continue;
if (!st[nx][ny]) {
st[nx][ny] = 1;
q1.push({nx, ny});
}
}
}
now += 1;
}
printf("%d\n", ans);
return 0;
}
vjudge1