結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2016-07-22 23:06:39 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 706 ms / 3,000 ms |
コード長 | 1,073 bytes |
コンパイル時間 | 721 ms |
コンパイル使用メモリ | 73,832 KB |
実行使用メモリ | 121,172 KB |
最終ジャッジ日時 | 2024-11-06 12:59:29 |
合計ジャッジ時間 | 4,473 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <iostream>#include <vector>#include <cstring>#include <string>#include <algorithm>#include <iomanip>#include <queue>using namespace std;const int INF = 1000000;char b[3010][3010];int d[3010][3010];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(1 <= nx && nx <= W && 1 <= 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;}