結果
問題 | No.402 最も海から遠い場所 |
ユーザー | tottoripaper |
提出日時 | 2016-10-23 19:20:10 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 375 ms / 3,000 ms |
コード長 | 1,598 bytes |
コンパイル時間 | 1,309 ms |
コンパイル使用メモリ | 154,760 KB |
実行使用メモリ | 122,076 KB |
最終ジャッジ日時 | 2023-08-15 18:04:05 |
合計ジャッジ時間 | 4,258 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
38,784 KB |
testcase_01 | AC | 9 ms
38,972 KB |
testcase_02 | AC | 11 ms
38,820 KB |
testcase_03 | AC | 10 ms
38,872 KB |
testcase_04 | AC | 10 ms
38,832 KB |
testcase_05 | AC | 11 ms
38,784 KB |
testcase_06 | AC | 10 ms
38,904 KB |
testcase_07 | AC | 10 ms
38,948 KB |
testcase_08 | AC | 11 ms
38,804 KB |
testcase_09 | AC | 11 ms
38,772 KB |
testcase_10 | AC | 11 ms
38,772 KB |
testcase_11 | AC | 10 ms
38,844 KB |
testcase_12 | AC | 10 ms
38,788 KB |
testcase_13 | AC | 13 ms
39,216 KB |
testcase_14 | AC | 11 ms
38,876 KB |
testcase_15 | AC | 20 ms
40,056 KB |
testcase_16 | AC | 23 ms
40,232 KB |
testcase_17 | AC | 198 ms
61,548 KB |
testcase_18 | AC | 375 ms
52,508 KB |
testcase_19 | AC | 301 ms
122,076 KB |
testcase_20 | AC | 281 ms
48,424 KB |
testcase_21 | AC | 276 ms
86,596 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:76:11: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized] printf("%d\n", res); ~~~~~~^~~~~~~~~~~~~
ソースコード
#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); }