結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
|
提出日時 | 2020-11-17 18:41:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 775 ms / 3,000 ms |
コード長 | 1,500 bytes |
コンパイル時間 | 1,271 ms |
コンパイル使用メモリ | 103,780 KB |
実行使用メモリ | 165,908 KB |
最終ジャッジ日時 | 2024-07-23 08:24:26 |
合計ジャッジ時間 | 4,861 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <iostream> #include <string> #include <algorithm> #include <iostream> #include <string> #include <algorithm> #include <vector> #include <iomanip> #include <cmath> #include <stdio.h> #include <queue> #include <deque> #include <cstdio> #include <set> #include <map> #include <bitset> #include <stack> #include <cctype> using namespace std; int ans[3030][3030]; string s[3030]; int x2[8] = { 0,0,1,-1,1,1,-1,-1 }; int y2[8] = { 1,-1,0,0,1,-1,1,-1 }; int main() { int h, w; cin >> h >> w; for (int i = 1; i <= h; i++) { cin >> s[i]; s[i] = '.' + s[i] + '.'; } s[0] = ""; s[h + 1] = ""; for (int i = 0; i < w + 2; i++) { s[0] += '.'; s[h + 1] += '.'; } queue<tuple<int, int, int>> que; for (int i = 0; i < h + 2; i++) { for (int j = 0; j < w + 2; j++) { if (s[i][j] == '.') { que.push(make_tuple(0, i, j)); ans[i][j] = 0; } else { ans[i][j] = -1; } } } while (!que.empty()) { tuple<int, int, int> t = que.front(); que.pop(); int x = get<1>(t); int y = get<2>(t); int z = get<0>(t); for (int i = 0; i < 8; i++) { if (x + x2[i] < 0 || x + x2[i] >= h + 2 || y + y2[i] < 0 || y + y2[i] >= w + 2) { continue; } if (ans[x + x2[i]][y + y2[i]] == -1) { ans[x + x2[i]][y + y2[i]] = z + 1; que.push(make_tuple(z + 1, x + x2[i], y + y2[i])); } } } int ans1 = -1; for (int i = 0; i < h + 2; i++) { for (int j = 0; j < w + 2; j++) { if (ans1 < ans[i][j]) { ans1 = ans[i][j]; } } } cout << ans1 << endl; }