結果
問題 |
No.402 最も海から遠い場所
|
ユーザー |
![]() |
提出日時 | 2016-10-23 19:20:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 613 ms / 3,000 ms |
コード長 | 1,598 bytes |
コンパイル時間 | 1,561 ms |
コンパイル使用メモリ | 168,804 KB |
実行使用メモリ | 122,236 KB |
最終ジャッジ日時 | 2024-11-24 02:04:40 |
合計ジャッジ時間 | 5,561 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define fst(t) std::get<0>(t) #define snd(t) std::get<1>(t) #define thd(t) std::get<2>(t) using ll = long long; using P = std::tuple<int,int>; const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1}; string ma[3000]; int dist[3002][3002]; stack<P> st, st2; int main(){ //* std::cin.tie(nullptr); std::ios::sync_with_stdio(false); /*/ /*/ int H, W; std::cin >> H >> W; memset(dist, -1, sizeof(dist)); for(int i=0;i<=H+1;++i){ dist[i][0] = 0; dist[i][W+1] = 0; st.emplace(i, 0); st.emplace(i, W+1); } for(int i=0;i<=W+1;++i){ dist[0][i] = 0; dist[H+1][i] = 0; st.emplace(0, i); st.emplace(H+1, i); } for(int i=0;i<H;++i){ std::cin >> ma[i]; for(int j=0;j<W;++j){ if(ma[i][j] == '.'){ dist[i+1][j+1] = 0; st.emplace(i+1, j+1); } } } int res; while(!st.empty()){ while(!st.empty()){ int y, x; tie(y, x) = st.top(); st.pop(); for(int i=0;i<8;++i){ int ny = y + dy[i], nx = x + dx[i]; if(1 <= nx && nx <= W && 1 <= ny && ny <= H && dist[ny][nx] == -1){ dist[ny][nx] = dist[y][x] + 1; res = dist[ny][nx]; st2.emplace(ny, nx); } } } swap(st, st2); } printf("%d\n", res); }