結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2019-07-11 12:57:10 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 1,251 bytes |
コンパイル時間 | 1,713 ms |
コンパイル使用メモリ | 172,364 KB |
実行使用メモリ | 823,804 KB |
最終ジャッジ日時 | 2024-11-07 12:56:06 |
合計ジャッジ時間 | 9,532 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 MLE * 1 -- * 3 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #ifdef LOCAL_DEBUG #include "LOCAL_DEBUG.hpp" #endif char table[3003][3003]; int mp[3003][3003]; queue<pair<int,int>> q; const int INF = 1 << 30; signed main(){ int h,w; cin >> h >> w; for(int i = 0; i <= h+1; i++){ for(int j = 0; j <= w+1; j++){ if(i == 0 || j == 0 || i == h+1 || j == w+1){ q.push({i,j}); continue; } char c; cin >> c; table[i][j] = c; if(table[i][j] == '.'){ q.push({i,j}); } else mp[i][j] = INF; } } while(!q.empty()){ auto p = q.front(); q.pop(); for(int dx : {-1,0,1}){ for(int dy : {-1,0,1}){ int ny = p.first + dy; int nx = p.second + dx; if(ny < 0 || h+1 < ny || nx < 0 || w+1 < nx) continue; if(mp[ny][nx] == INF) q.push({ny,nx}); if((ny == 1 || ny == h || nx == 1 || nx == w) && table[ny][nx] == '#') mp[ny][nx] = 1; if(1 <= ny && ny <= h && 1 <= nx && nx <= w) mp[p.first][p.second] = min(mp[p.first][p.second],mp[ny][nx]+1); } } } int ans = 0; for(int i = 0; i <= h; i++){ for(int j = 0; j <= w; j++){ ans = max(ans,mp[i][j]); } } cout << ans << endl; return 0; }