結果
問題 |
No.86 TVザッピング(2)
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:29:37 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,141 bytes |
コンパイル時間 | 195 ms |
コンパイル使用メモリ | 82,368 KB |
実行使用メモリ | 70,408 KB |
最終ジャッジ日時 | 2025-06-20 14:02:09 |
合計ジャッジ時間 | 2,884 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 WA * 8 |
ソースコード
import sys from collections import deque def main(): input = sys.stdin.read().split() n = int(input[0]) m = int(input[1]) grid = input[2:] 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: 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 found = 1 dirs = [(-1,0), (1,0), (0,-1), (0,1)] while q: i, j = q.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 not visited[ni][nj]: visited[ni][nj] = True found += 1 q.append((ni, nj)) if found == count: print("YES") else: print("NO") if __name__ == "__main__": main()