結果
| 問題 | No.179 塗り分け |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-17 18:57:23 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 16 ms / 3,000 ms |
| コード長 | 2,165 bytes |
| 記録 | |
| コンパイル時間 | 932 ms |
| コンパイル使用メモリ | 107,948 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-12 07:06:44 |
| 合計ジャッジ時間 | 1,894 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 40 |
ソースコード
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 = Matrix!(immutable(char))(h.iota.map!(_ => readln.chomp).array);
auto s = {
foreach (p; sij.points!int)
if (sij[p] == '#') return p;
return point(-1, -1);
}();
if (s == point(-1, -1)) {
writeln("NO");
return;
}
auto canPaint(point p) {
auto d = p - s;
auto tij = Matrix!bool(h, w);
tij[s] = tij[p] = true;
foreach (ip; sij.points!int)
if (sij[ip] == '#' && !tij[ip]) {
auto np = d + ip;
if (!sij.validIndex(np) || sij[np] != '#' || tij[np])
return false;
tij[ip] = tij[np] = true;
}
return true;
}
auto r = {
foreach (y; s.y..h)
foreach (x; 0..w) {
auto p = point(x, y);
if (s != p && sij[p] == '#' && canPaint(p))
return true;
}
return false;
}();
writeln(r ? "YES" : "NO");
}
struct Point(T)
{
T x, y;
pure auto opBinary(string op: "+")(const Point!T rhs) const { return Point!T(x + rhs.x, y + rhs.y); }
pure auto opBinary(string op: "-")(const Point!T rhs) const { return Point!T(x - rhs.x, y - rhs.y); }
}
struct Matrix(T)
{
import std.algorithm, std.conv, std.range, std.traits, std.typecons;
T[][] m;
const size_t rows, cols;
mixin Proxy!m;
this(size_t r, size_t c) { rows = r; cols = c; m = new T[][](rows, cols); }
this(T[][] s) { rows = s.length; cols = s[0].length; m = s; }
pure auto opIndex(U)(const Point!U p) const { return m[p.y][p.x]; }
pure auto opIndex(U)(U y) if (!is(U == Point!V, V)) { return m[y]; }
pure auto opIndex(size_t y, size_t x) const { return m[y][x]; }
static if (isAssignable!T) {
auto opIndexAssign(U)(T v, const Point!U p) { return m[p.y][p.x] = v; }
auto opIndexAssign(T v, size_t y, size_t x) { return m[y][x] = v; }
}
pure auto validIndex(U)(const Point!U p) const { return p.x >= 0 && p.x < cols && p.y >= 0 && p.y < rows; }
pure auto points(U)() const { return rows.to!U.iota.map!(y => cols.to!U.iota.map!(x => Point!U(x, y))).joiner; }
}