結果
問題 | No.402 最も海から遠い場所 |
ユーザー | ei1333333 |
提出日時 | 2016-07-22 22:47:28 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 457 ms / 3,000 ms |
コード長 | 2,629 bytes |
コンパイル時間 | 1,376 ms |
コンパイル使用メモリ | 165,164 KB |
実行使用メモリ | 56,504 KB |
最終ジャッジ日時 | 2024-04-24 05:49:03 |
合計ジャッジ時間 | 4,478 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 14 ms
38,584 KB |
testcase_01 | AC | 13 ms
38,740 KB |
testcase_02 | AC | 14 ms
38,776 KB |
testcase_03 | AC | 13 ms
38,668 KB |
testcase_04 | AC | 13 ms
38,848 KB |
testcase_05 | AC | 13 ms
38,728 KB |
testcase_06 | AC | 13 ms
38,832 KB |
testcase_07 | AC | 14 ms
38,796 KB |
testcase_08 | AC | 14 ms
38,764 KB |
testcase_09 | AC | 13 ms
38,740 KB |
testcase_10 | AC | 13 ms
38,796 KB |
testcase_11 | AC | 13 ms
38,676 KB |
testcase_12 | AC | 13 ms
38,680 KB |
testcase_13 | AC | 17 ms
38,736 KB |
testcase_14 | AC | 14 ms
38,716 KB |
testcase_15 | AC | 28 ms
39,088 KB |
testcase_16 | AC | 31 ms
39,456 KB |
testcase_17 | AC | 289 ms
47,348 KB |
testcase_18 | AC | 454 ms
56,420 KB |
testcase_19 | AC | 246 ms
56,428 KB |
testcase_20 | AC | 457 ms
56,504 KB |
testcase_21 | AC | 300 ms
56,376 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; const int INF = 1 << 30; int H, W; string S[3003]; int dist[3004][3004]; int main() { cin >> H >> W; for(int i = 1; i <= H; i++) { cin >> S[i]; S[i] = "." + S[i] + "."; } S[0] = S[H + 1] = string(W + 2, '.'); int ret = 0; fill_n(*dist, 3004 * 3004, INF); for(int i = 0; i <= H + 1; i++) { for(int j = 0; j <= W + 1; j++) { if(S[i][j] == '.') dist[i][j] = 0; } } for(int i = 1; i <= H; i++) { for(int j = 1; j <= W; j++) { if(S[i][j] == '#') { dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j - 1] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j + 1] + 1); } } } for(int i = H; i > 0; i--) { for(int j = W; j > 0; j--) { if(S[i][j] == '#') { dist[i][j] = min(dist[i][j], dist[i][j + 1] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j + 1] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j - 1] + 1); } } } for(int i = 1; i <= H; i++) { for(int j = 1; j <= W; j++) { if(S[i][j] == '#') { dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j - 1] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j + 1] + 1); } } } for(int i = H; i > 0; i--) { for(int j = W; j > 0; j--) { if(S[i][j] == '#') { dist[i][j] = min(dist[i][j], dist[i][j + 1] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j + 1] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j - 1] + 1); } } } for(int i = 1; i <= H; i++) { for(int j = 1; j <= W; j++) { if(S[i][j] == '#') { dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j - 1] + 1); dist[i][j] = min(dist[i][j], dist[i - 1][j + 1] + 1); } } } for(int i = H; i > 0; i--) { for(int j = W; j > 0; j--) { if(S[i][j] == '#') { dist[i][j] = min(dist[i][j], dist[i][j + 1] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j + 1] + 1); dist[i][j] = min(dist[i][j], dist[i + 1][j - 1] + 1); ret = max(ret, dist[i][j]); } } } cout << ret << endl; }