結果

問題 No.402 最も海から遠い場所
ユーザー nebukuro09nebukuro09
提出日時 2016-11-04 14:55:55
言語 D
(dmd 2.106.1)
結果
MLE  
実行時間 -
コード長 1,279 bytes
コンパイル時間 901 ms
コンパイル使用メモリ 103,364 KB
実行使用メモリ 686,456 KB
最終ジャッジ日時 2023-09-02 22:46:20
合計ジャッジ時間 9,340 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,740 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 6 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 1 ms
4,368 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 2 ms
4,368 KB
testcase_09 AC 2 ms
4,368 KB
testcase_10 AC 2 ms
4,368 KB
testcase_11 AC 4 ms
4,368 KB
testcase_12 AC 3 ms
4,372 KB
testcase_13 AC 58 ms
12,108 KB
testcase_14 AC 25 ms
5,740 KB
testcase_15 AC 355 ms
58,704 KB
testcase_16 AC 716 ms
78,628 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.stdio;
import std.array;
import std.string;
import std.conv;
import std.algorithm;
import std.typecons;
import std.range;
import std.random;
import std.math;
import std.container;

void main() {
  auto input = readln.split.map!(to!int);
  int H = input[0];
  int W = input[1];
  auto B = new string[](H+2);

  B[0] = replicate(".", W+2);
  foreach (i; iota(1, H+1))
    B[i] = "." ~ readln.chomp ~ ".";
  B[H+1] = replicate(".", W+2);

  DList!(Tuple!(int, int, int)) queue;
  foreach (i; iota(H+2))
    foreach (j; iota(W+2))
      if (B[i][j] == '.')
        queue.insert(tuple(i, j, 0));
  bool[int][int] visited;

  int ans = 0;
  int r, c, depth, nr, nc;
  int[8] dx = [-1, 0, 1, -1, 1, -1, 0, 1];
  int[8] dy = [-1, -1, -1, 0, 0, 1, 1, 1];
  while (!queue.empty) {
    auto node = queue.front;
    r = node[0];
    c = node[1];
    depth = node[2];
    queue.removeFront;
    if (r in visited && c in visited[r])
      continue;
    ans = max(ans, depth);
    visited[r][c] = true;

    foreach (d; iota(8)) {
      nr = r + dx[d];
      nc = c + dy[d];
      if (nr < 0 || nr >= H+2 || nc < 0 || nc >= W+2)
        continue;
      if (nr in visited && nc in visited[nr])
        continue;
      queue.insert(tuple(nr, nc, depth+1));
    }
  }
  writeln(ans);
}
0