結果

問題 No.86 TVザッピング(2)
ユーザー gew1fw
提出日時 2025-06-12 18:01:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 876 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,692 KB
実行使用メモリ 67,328 KB
最終ジャッジ日時 2025-06-20 14:02:50
合計ジャッジ時間 2,542 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

n, m = map(int, input().split())
grid = [input().strip() for _ in range(n)]

count = 0
start = None
for i in range(n):
    for j in range(m):
        if grid[i][j] == '.':
            count += 1
            if start is None:
                start = (i, j)

if count % 2 != 0 or count == 0:
    print("NO")
else:
    visited = [[False]*m for _ in range(n)]
    from collections import deque
    q = deque()
    if start:
        q.append(start)
        visited[start[0]][start[1]] = True
    found = 0
    dirs = [(-1,0), (1,0), (0,-1), (0,1)]
    while q:
        i, j = q.popleft()
        found += 1
        for di, dj in dirs:
            ni, nj = i + di, j + dj
            if 0 <= ni < n and 0 <= nj < m and not visited[ni][nj] and grid[ni][nj] == '.':
                visited[ni][nj] = True
                q.append((ni, nj))
    print("YES" if found == count else "NO")
0