結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 18:00:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,367 bytes |
| コンパイル時間 | 178 ms |
| コンパイル使用メモリ | 82,648 KB |
| 実行使用メモリ | 77,332 KB |
| 最終ジャッジ日時 | 2025-06-20 14:02:48 |
| 合計ジャッジ時間 | 2,818 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 6 |
ソースコード
import sys
from collections import deque
def main():
N, M = map(int, sys.stdin.readline().split())
grid = [sys.stdin.readline().strip() for _ in range(N)]
cells = []
for i in range(N):
for j in range(M):
if grid[i][j] == '.':
cells.append((i, j))
K = len(cells)
if K % 2 != 0:
print("NO")
return
if K == 0:
print("NO")
return
# Check connectivity using BFS
visited = set()
start = cells[0]
queue = deque([start])
visited.add(start)
dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while queue:
i, j = queue.popleft()
for di, dj in dirs:
ni, nj = i + di, j + dj
if 0 <= ni < N and 0 <= nj < M:
if grid[ni][nj] == '.' and (ni, nj) not in visited:
visited.add((ni, nj))
queue.append((ni, nj))
if len(visited) != K:
print("NO")
return
# Check if spans at least two rows and two columns
min_row = min(i for i, j in cells)
max_row = max(i for i, j in cells)
min_col = min(j for i, j in cells)
max_col = max(j for i, j in cells)
if (max_row - min_row >= 1) and (max_col - min_col >= 1):
print("YES")
else:
print("NO")
if __name__ == "__main__":
main()
gew1fw