結果
問題 |
No.86 TVザッピング(2)
|
ユーザー |
![]() |
提出日時 | 2025-04-15 21:54:09 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,276 bytes |
コンパイル時間 | 192 ms |
コンパイル使用メモリ | 82,360 KB |
実行使用メモリ | 69,248 KB |
最終ジャッジ日時 | 2025-06-20 14:02:06 |
合計ジャッジ時間 | 2,849 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 8 |
ソースコード
import sys from collections import deque def main(): input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 M = int(input[idx]) idx += 1 grid = [] viewable = [] total = 0 start = None for i in range(N): line = input[idx] idx += 1 grid.append(line) for j in range(M): if line[j] == '.': total += 1 if start is None: start = (i, j) if total % 2 != 0: print("NO") return if start is None: print("NO") return visited = [[False for _ in range(M)] for __ in range(N)] q = deque() q.append(start) visited[start[0]][start[1]] = True count = 1 dirs = [(-1, 0), (1, 0), (0, -1), (0, 1)] while q: i, j = q.popleft() for di, dj in dirs: ni = i + di nj = 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 q.append((ni, nj)) if count == total: print("YES") else: print("NO") if __name__ == "__main__": main()