結果
| 問題 | 
                            No.1588 Connection
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2021-07-12 17:41:43 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 231 ms / 2,000 ms | 
| コード長 | 914 bytes | 
| コンパイル時間 | 274 ms | 
| コンパイル使用メモリ | 82,104 KB | 
| 実行使用メモリ | 95,800 KB | 
| 平均クエリ数 | 551.19 | 
| 最終ジャッジ日時 | 2024-07-17 13:02:39 | 
| 合計ジャッジ時間 | 5,306 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 31 | 
ソースコード
from collections import deque
n, m = map(int, input().split())
sx, sy = 0, 0
gx, gy = n - 1, n - 1
INF = 10 ** 18
def bfs():
    d = [[-1] * n for i in range(n)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
 
    que = deque([])
    que.append((sy, sx))
    d[sy][sx] = 0
 
    while que:
        p = que.popleft()
        if p[0] == gy and p[1] == gx:
            exit(print("Yes"))
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if nx == n - 1 and ny == n - 1: exit(print("Yes"))
            if 0 <= nx < n and 0 <= ny < n and d[nx][ny] == -1:
                print(nx + 1, ny + 1)
                res = input()
                if res == "Black":
                    que.append((nx, ny))
                    d[nx][ny] = 0
                    
                else:
                    d[nx][ny] = 1
    return d[gy][gx]
print("Yes" if bfs() == 0 else "No")