結果
| 問題 | 
                            No.1588 Connection
                             | 
                    
| コンテスト | |
| ユーザー | 
                             Kiri8128
                         | 
                    
| 提出日時 | 2021-07-08 23:30:14 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 247 ms / 2,000 ms | 
| コード長 | 806 bytes | 
| コンパイル時間 | 275 ms | 
| コンパイル使用メモリ | 82,300 KB | 
| 実行使用メモリ | 98,272 KB | 
| 平均クエリ数 | 562.59 | 
| 最終ジャッジ日時 | 2024-07-17 12:35:14 | 
| 合計ジャッジ時間 | 5,553 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 31 | 
ソースコード
from collections import deque
N, M = map(int, input().split())
memo = [-1] * (N * N)
memo[0] = 1
memo[-1] = 1
def chk(x):
    if memo[x] >= 0: return memo[x]
    i, j = x // N, x % N
    print(i + 1, j + 1)
    a = input()
    if a == "Black":
        memo[x] = 1
        return 1
    memo[x] = 0
    return 0
    
def BFS(n):
    Q = deque([0])
    D = [-1] * n
    D[0] = 0
    while Q:
        x = Q.popleft()
        i, j = x // N, x % N
        for di, dj in ((0, 1), (1, 0), (-1, 0), (0, -1)):
            ni, nj = i + di, j + dj
            if not 0 <= ni < N: continue
            if not 0 <= nj < N: continue
            y = ni * N + nj
            if D[y] == -1 and chk(y):
                D[y] = D[x] + 1
                Q.append(y)
    return "Yes" if D[-1] >= 0 else "No"
print(BFS(N * N))
            
            
            
        
            
Kiri8128