結果
| 問題 | 
                            No.179 塗り分け
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2016-08-31 17:08:25 | 
| 言語 | D  (dmd 2.109.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 14 ms / 3,000 ms | 
| コード長 | 1,339 bytes | 
| コンパイル時間 | 1,064 ms | 
| コンパイル使用メモリ | 120,320 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-06-12 04:01:44 | 
| 合計ジャッジ時間 | 1,737 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 6 | 
| other | AC * 40 | 
ソースコード
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random;
import std.string, std.conv, std.stdio, std.typecons;
struct point {
  int x;
  int y;
  point opBinary(string op)(point rhs) {
    static if (op == "+") return point(x + rhs.x, y + rhs.y);
    else static if (op == "-") return point(x - rhs.x, y - rhs.y);
  }
}
void main()
{
  auto rd = readln.split.map!(to!int);
  auto h = rd[0], w = rd[1];
  auto aij = iota(h).map!(_ => readln.chomp.map!(c => c == '#').array).array;
  writeln(calc(h, w, aij) ? "YES" : "NO");
}
bool calc(int h, int w, bool[][] aij)
{
  bool valid(point p) {
    return p.x >= 0 && p.x < w && p.y >= 0 && p.y < h;
  }
  point[] pi;
  foreach (i; 0..h)
    foreach (j; 0..w)
      if (aij[i][j])
        pi ~= point(j, i);
  if (pi.empty)
    return false;
  auto bp = pi.front;
  auto di = pi[1..$].map!(p => p - bp);
  return di.any!((d) {
    auto visited = new bool[][](h, w);
    return pi.all!((p) {
      if (visited[p.y][p.x]) {
        return true;
      } else {
        auto q = p + d;
        if (!valid(q) || !aij[q.y][q.x] || visited[q.y][q.x]) {
          return false;
        } else {
          visited[p.y][p.x] = true;
          visited[q.y][q.x] = true;
          return true;
        }
      }
    });
  });
}