結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-04-12 10:34:40 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 1,971 bytes |
| コンパイル時間 | 597 ms |
| コンパイル使用メモリ | 109,624 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 13:59:57 |
| 合計ジャッジ時間 | 1,424 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
void main() {
auto s = readln.split.map!(to!int);
auto H = s[0];
auto W = s[1];
auto A = H.iota.map!(_ => readln.chomp).array;
int U = 100000;
int D = -1;
int L = 100000;
int R = -1;
foreach (r; 0..H) {
foreach (c; 0..W) {
if (A[r][c] == '#') continue;
U = min(U, r);
D = max(D, r);
L = min(L, c);
R = max(R, c);
}
}
if (U == D || L == R) {
writeln("NO");
return;
}
int num = (R - L + 1) * 2 + (D - U + 1) * 2 - 4;
if (A.map!(r => r.map!(a => a == '.').sum).sum != num) {
writeln("NO");
return;
}
bool row(int r, int c1, int c2) {
return A[r][c1..c2+1].map!(a => a == '.').all;
}
bool col(int c, int r1, int r2) {
return A[r1..r2+1].map!(a => a[c] == '.').all;
}
bool u = row(U, L, R);
bool d = row(D, L, R);
bool l = col(L, U, D);
bool r = col(R, U, D);
if (u && d && l && r) {
writeln("YES");
return;
}
foreach (i; U+1..D) {
foreach (j; L+1..R) {
if (d && r && row(U, j, R) && row(i, L, j) && col(L, i, D) && col(j, U, i)) {
writeln("YES");
return;
}
if (d && l && row(U, L, j) && row(i, j, R) && col(j, U, i) && col(R, i, D)) {
writeln("YES");
return;
}
if (u && l && row(i, j, R) && row(D, L, j) && col(R, U, i) && col(j, i, D)) {
writeln("YES");
return;
}
if (u && r && row(i, L, j) && row(D, j, R) && col(L, U, i) && col(j, i, D)) {
writeln("YES");
return;
}
}
}
writeln("NO");
}