結果

問題 No.1588 Connection
ユーザー H3PO4
提出日時 2021-07-08 23:25:26
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 165 ms / 2,000 ms
コード長 746 bytes
コンパイル時間 78 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 29,528 KB
平均クエリ数 559.75
最終ジャッジ日時 2024-07-17 12:33:47
合計ジャッジ時間 4,508 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

N, M = map(int, input().split())
d = deque([(0, 0)])
table = [[None] * N for _ in range(N)]
table[0][0] = True


def query(x, y):
    print(x, y, flush=True)
    T = input()
    if T == 'Black':
        return True
    elif T == 'White':
        return False
    else:
        raise ValueError


while d:
    x, y = d.pop()
    if x == N - 1 and y == N - 1:
        print('Yes', flush=True)
        exit()
    for dx, dy in ((1, 0), (0, 1), (-1, 0), (0, -1)):
        xdx, ydy = x + dx, y + dy
        if 0 <= xdx < N and 0 <= ydy < N and table[xdx][ydy] is None:
            T = query(xdx + 1, ydy + 1)
            table[xdx][ydy] = T
            if T:
                d.append((xdx, ydy))
print('No', flush=True)
0