結果

問題 No.402 最も海から遠い場所
ユーザー y_mazuny_mazun
提出日時 2017-01-20 15:12:52
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,078 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 48,992 KB
実行使用メモリ 120,176 KB
最終ジャッジ日時 2023-08-24 18:17:51
合計ジャッジ時間 5,045 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
38,856 KB
testcase_01 WA -
testcase_02 AC 11 ms
39,004 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 11 ms
38,840 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 11 ms
38,756 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 11 ms
38,860 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 24 ms
41,172 KB
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 636 ms
50,880 KB
testcase_19 AC 443 ms
120,176 KB
testcase_20 WA -
testcase_21 AC 398 ms
83,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

#include <cstring>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int d[3000][3000];
char g[3000][3010];

int main(){
  const int h = getInt();
  const int w = getInt();

  REP(i,h) scanf("%s", g[i]);

  memset(d, -1, sizeof(d));
  queue<pair<int, int> > q;

  REP(i,h) REP(j,w) if(g[i][j] == '.') {
    d[i][j] = 0;
    q.push(make_pair(j, i));
  }

  while (q.size()){
    const auto data = q.front (); q.pop();
    const int x = data.first;
    const int y = data.second;

    REP(i,3) REP(j,3) {
      const int xx = x + i - 1;
      const int yy = y + j - 1;
      if(ISIN(xx, yy, w, h) && d[yy][xx] == -1){
	q.push(make_pair(xx, yy));
	d[yy][xx] = d[y][x] + 1;
      }
    }
  }

  // REP(i,h) { REP(j,w) printf("%02d ", d[i][j]); puts(""); }
  int ans = 0;
  REP(i,h) REP(j,w) ans = max(ans, d[i][j]);
  printf("%d\n", ans);

  return 0;
}
0