結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2019-12-12 21:15:29 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 547 ms / 3,000 ms |
コード長 | 1,707 bytes |
コンパイル時間 | 1,587 ms |
コンパイル使用メモリ | 172,692 KB |
実行使用メモリ | 122,252 KB |
最終ジャッジ日時 | 2024-06-25 15:36:50 |
合計ジャッジ時間 | 4,762 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h>using namespace std;typedef pair<int, int> P;int H, W;char S[3100][3100];int dist[3100][3100];void bfs() {queue<P> q;for (int i=0; i<H+2; i++) {for (int j=0; j<W+2; j++) {if (S[i][j]=='.') {q.push(P(i, j));dist[i][j] = 0;}else {dist[i][j] = -1;}}}while (q.size()) {P p = q.front(); q.pop();int cx=p.first, cy=p.second;for (int i=-1; i<=1; i++) {for (int j=-1; j<=1; j++) {int nx=cx+i, ny=cy+j;if (!(0<=nx && nx<H+2 && 0<=ny && ny<W+2)) {continue;}if (dist[nx][ny]==-1) {dist[nx][ny] = dist[cx][cy]+1;q.push(P(nx, ny));}}}}}int main() {cin.tie(0); ios::sync_with_stdio(false);cin >> H >> W;for (int i=0; i<H+2; i++) {if (i==0 || i==H+1) {for (int j=0; j<W+2; j++) {S[i][j] = '.';}}else {string Si; cin >> Si;for (int j=0; j<W+2; j++) {if (j==0 || j==W+1) {S[i][j] = '.';}else {S[i][j] = Si[j-1];}}}}bfs();int ans = 0;for (int i=0; i<H+2; i++) {for (int j=0; j<W+2; j++) {ans = max(ans, dist[i][j]);}}cout << ans << endl;}