結果

問題 No.402 最も海から遠い場所
ユーザー oxyshoweroxyshower
提出日時 2019-07-11 13:03:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,889 ms
コンパイル使用メモリ 169,220 KB
実行使用メモリ 815,748 KB
最終ジャッジ日時 2024-04-25 03:22:04
合計ジャッジ時間 9,960 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 4 ms
5,248 KB
testcase_03 WA -
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 24 ms
6,528 KB
testcase_14 AC 17 ms
6,272 KB
testcase_15 AC 117 ms
16,640 KB
testcase_16 AC 286 ms
28,332 KB
testcase_17 AC 2,110 ms
202,996 KB
testcase_18 MLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

char table[3003][3003];
int mp[3003][3003];
queue<pair<int,int>> q;
const int INF = 1 << 30;

signed main(){

  int h,w; cin >> h >> w;
  for(int i = 0; i <= h+1; i++){
    for(int j = 0; j <= w+1; j++){
      if(i == 0 || j == 0 || i == h+1 || j == w+1){
        q.push({i,j});
        continue;
      }
      char c; scanf("%c",&c);
      table[i][j] = c;
      if(table[i][j] == '.'){
        q.push({i,j});
      }
      else mp[i][j] = INF;
     }
  }

  while(!q.empty()){
    auto p = q.front(); q.pop();
    for(int dx : {-1,0,1}){
      for(int dy : {-1,0,1}){
        int ny = p.first + dy;
        int nx = p.second + dx;
        if(ny < 0 || h+1 < ny || nx < 0 || w+1 < nx) continue;
        if(mp[ny][nx] == INF && !(dx == 0 && dy == 0)) q.push({ny,nx});
        if((ny == 1 || ny == h || nx == 1 || nx == w) && table[ny][nx] == '#') mp[ny][nx] = 1;
        if(1 <= ny && ny <= h && 1 <= nx && nx <= w){
          mp[p.first][p.second] = min(mp[p.first][p.second],mp[ny][nx]+1);
        }
      }
    }
  }

  int ans = 0;
  for(int i = 0; i <= h; i++){
    for(int j = 0; j <= w; j++){
      ans = max(ans,mp[i][j]);
    }
  }
  cout << ans << endl;

  return 0;
}
0