結果

問題 No.179 塗り分け
ユーザー te-shte-sh
提出日時 2017-02-08 14:27:34
言語 D
(dmd 2.107.1)
結果
AC  
実行時間 15 ms / 3,000 ms
コード長 1,503 bytes
コンパイル時間 1,963 ms
コンパイル使用メモリ 94,624 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-03 01:25:07
合計ジャッジ時間 2,660 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 15 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 9 ms
4,380 KB
testcase_21 AC 3 ms
4,380 KB
testcase_22 AC 4 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 3 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 6 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 8 ms
4,376 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 10 ms
4,376 KB
testcase_32 AC 4 ms
4,380 KB
testcase_33 AC 10 ms
4,376 KB
testcase_34 AC 3 ms
4,380 KB
testcase_35 AC 11 ms
4,380 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 1 ms
4,384 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 2 ms
4,380 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

alias Point!int point;

void main()
{
  auto rd = readln.split.to!(int[]), h = rd[0], w = rd[1];
  auto sij = h.iota.map!(_ => readln.chomp).array;

  auto s = {
    foreach (y; 0..h)
      foreach (x; 0..w)
        if (sij[y][x] == '#') return point(x, y);
    return point(-1, -1);
  }();

  if (s == point(-1, -1)) {
    writeln("NO");
    return;
  }

  auto canPaint(int x, int y) {
    auto d = point(x, y) - s;
    auto tij = new bool[][](h, w);
    tij[s.y][s.x] = tij[y][x] = true;
    foreach (iy; 0..h)
      foreach (ix; 0..w)
        if (sij[iy][ix] == '#' && !tij[iy][ix]) {
          auto ip = d + point(ix, iy);
          if (ip.x < 0 || ip.x >= w || ip.y >= h || sij[ip.y][ip.x] != '#' || tij[ip.y][ip.x])
            return false;
          tij[iy][ix] = tij[ip.y][ip.x] = true;
        }
    return true;
  }

  auto r = {
    foreach (y; s.y..h)
      foreach (x; 0..w)
        if (s != point(x, y) && sij[y][x] == '#' && canPaint(x, y))
          return true;
    return false;
  }();

  writeln(r ? "YES" : "NO");
}

struct Point(T) {
  T x, y;

  auto opBinary(string op: "+")(Point!T rhs) { return Point!T(x + rhs.x, y + rhs.y); }
  auto opBinary(string op: "-")(Point!T rhs) { return Point!T(x - rhs.x, y - rhs.y); }
  auto opBinary(string op: "*")(Point!T rhs) { return x * rhs.x + y * rhs.y; }
  auto opBinary(string op: "*")(T a) { return Point!T(x * a, y * a); }

  T hypot2() { return x ^^ 2 + y ^^ 2; }
}
0