結果

問題 No.402 最も海から遠い場所
ユーザー ei1333333ei1333333
提出日時 2016-07-22 22:45:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,215 bytes
コンパイル時間 1,341 ms
コンパイル使用メモリ 161,604 KB
実行使用メモリ 56,428 KB
最終ジャッジ日時 2024-04-24 05:48:04
合計ジャッジ時間 3,894 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
38,784 KB
testcase_01 AC 13 ms
38,796 KB
testcase_02 AC 13 ms
38,784 KB
testcase_03 AC 14 ms
38,752 KB
testcase_04 AC 14 ms
38,784 KB
testcase_05 AC 14 ms
38,528 KB
testcase_06 WA -
testcase_07 AC 13 ms
38,528 KB
testcase_08 AC 12 ms
38,688 KB
testcase_09 AC 13 ms
38,784 KB
testcase_10 AC 14 ms
38,784 KB
testcase_11 AC 14 ms
38,784 KB
testcase_12 AC 14 ms
38,784 KB
testcase_13 AC 14 ms
38,912 KB
testcase_14 AC 13 ms
38,844 KB
testcase_15 AC 22 ms
39,040 KB
testcase_16 AC 24 ms
39,516 KB
testcase_17 AC 189 ms
47,144 KB
testcase_18 AC 278 ms
56,416 KB
testcase_19 AC 205 ms
56,320 KB
testcase_20 AC 271 ms
56,192 KB
testcase_21 AC 225 ms
56,428 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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(H + 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);
        ret = max(ret, dist[i][j]);
      }
    }
  }
  cout << ret << endl;
}
0