結果
| 問題 |
No.86 TVザッピング(2)
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 12:50:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,181 bytes |
| コンパイル時間 | 160 ms |
| コンパイル使用メモリ | 82,292 KB |
| 実行使用メモリ | 69,260 KB |
| 最終ジャッジ日時 | 2025-06-20 14:02:28 |
| 合計ジャッジ時間 | 2,493 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 24 WA * 6 |
ソースコード
n, m = map(int, input().split())
grid = [input().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")
exit()
# Check if all cells are in the same row or column
same_row = True
row = cells[0][0]
for i, j in cells:
if i != row:
same_row = False
break
same_col = True
col = cells[0][1]
for i, j in cells:
if j != col:
same_col = False
break
if same_row or same_col:
print("NO")
exit()
# Check connectivity using BFS
from collections import deque
visited = [[False] * m for _ in range(n)]
start_i, start_j = cells[0]
queue = deque([(start_i, start_j)])
visited[start_i][start_j] = True
count = 1
directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
while queue:
i, j = queue.popleft()
for di, dj in directions:
ni, nj = i + di, j + dj
if 0 <= ni < n and 0 <= nj < m:
if grid[ni][nj] == '.' and not visited[ni][nj]:
visited[ni][nj] = True
count += 1
queue.append((ni, nj))
print("YES" if count == k else "NO")
gew1fw