結果

問題 No.1588 Connection
ユーザー noriocnorioc
提出日時 2021-07-09 01:47:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 794 bytes
コンパイル時間 84 ms
コンパイル使用メモリ 11,000 KB
実行使用メモリ 24,832 KB
平均クエリ数 552.31
最終ジャッジ日時 2023-09-24 11:56:42
合計ジャッジ時間 4,213 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
24,700 KB
testcase_01 AC 43 ms
24,404 KB
testcase_02 AC 44 ms
24,040 KB
testcase_03 AC 45 ms
24,084 KB
testcase_04 AC 44 ms
24,360 KB
testcase_05 AC 44 ms
24,092 KB
testcase_06 AC 45 ms
24,384 KB
testcase_07 AC 44 ms
24,764 KB
testcase_08 AC 48 ms
24,496 KB
testcase_09 AC 47 ms
24,352 KB
testcase_10 AC 48 ms
24,608 KB
testcase_11 AC 48 ms
24,108 KB
testcase_12 AC 88 ms
24,588 KB
testcase_13 AC 96 ms
24,432 KB
testcase_14 AC 44 ms
24,704 KB
testcase_15 AC 45 ms
24,104 KB
testcase_16 AC 44 ms
24,572 KB
testcase_17 AC 44 ms
24,380 KB
testcase_18 AC 43 ms
24,116 KB
testcase_19 AC 45 ms
24,732 KB
testcase_20 AC 45 ms
24,480 KB
testcase_21 AC 151 ms
24,348 KB
testcase_22 AC 151 ms
24,832 KB
testcase_23 AC 86 ms
24,184 KB
testcase_24 AC 68 ms
24,384 KB
testcase_25 AC 99 ms
24,744 KB
testcase_26 AC 97 ms
24,820 KB
testcase_27 AC 68 ms
24,760 KB
testcase_28 AC 61 ms
24,468 KB
testcase_29 AC 151 ms
24,628 KB
testcase_30 AC 153 ms
24,500 KB
testcase_31 AC 44 ms
24,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

N, M = map(int, input().split())

def query(r, c) -> bool:
    print(r, c)
    res = input()
    if res == '-1': exit()
    return res == 'Black'

def calc():
    q = collections.deque()
    q.append((1, 1))
    used = collections.defaultdict(bool)
    m = 0

    while len(q) > 0:
        r, c = q.popleft()
        if used[r, c]: continue
        used[r, c] = True
        if r == N and c == N: return True

        if m == 3000: return False
        black = query(r, c)
        m += 1

        if not black: continue
        for dr, dc in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
            if not (1 <= r + dr <= N): continue
            if not (1 <= c + dc <= N): continue
            q.append((r + dr, c + dc))

ans = calc()
if ans:
    print('Yes')
else:
    print('No')
0