結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
38,528 KB
testcase_01 AC 14 ms
38,528 KB
testcase_02 AC 14 ms
38,656 KB
testcase_03 WA -
testcase_04 AC 15 ms
38,628 KB
testcase_05 AC 13 ms
38,784 KB
testcase_06 WA -
testcase_07 AC 14 ms
38,784 KB
testcase_08 AC 15 ms
38,768 KB
testcase_09 AC 14 ms
38,784 KB
testcase_10 AC 26 ms
38,784 KB
testcase_11 AC 14 ms
38,512 KB
testcase_12 AC 14 ms
38,784 KB
testcase_13 AC 16 ms
38,912 KB
testcase_14 AC 14 ms
38,824 KB
testcase_15 AC 24 ms
39,168 KB
testcase_16 AC 25 ms
39,544 KB
testcase_17 AC 183 ms
47,104 KB
testcase_18 AC 269 ms
56,448 KB
testcase_19 AC 210 ms
56,448 KB
testcase_20 AC 276 ms
56,448 KB
testcase_21 AC 232 ms
56,448 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] = 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