結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2019-07-11 13:03:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,303 bytes |
コンパイル時間 | 1,551 ms |
コンパイル使用メモリ | 174,064 KB |
実行使用メモリ | 820,820 KB |
最終ジャッジ日時 | 2024-11-07 13:03:33 |
合計ジャッジ時間 | 10,308 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 9 WA * 6 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; scanf("%c",&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 && !(dx == 0 && dy == 0)) 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; }