結果

問題 No.1588 Connection
ユーザー mkawa2mkawa2
提出日時 2021-07-08 22:55:49
言語 Python3
(3.10.1 + numpy 1.22.3 + scipy 1.8.0)
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 62 ms
使用メモリ 24,924 KB
平均クエリ数 536.75
最終ジャッジ日時 2023-02-15 00:10:18
合計ジャッジ時間 4,088 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 36 ms
22,592 KB
testcase_01 AC 36 ms
22,404 KB
testcase_02 AC 36 ms
22,444 KB
testcase_03 AC 36 ms
22,604 KB
testcase_04 AC 37 ms
22,524 KB
testcase_05 AC 36 ms
22,820 KB
testcase_06 AC 37 ms
22,700 KB
testcase_07 AC 35 ms
22,496 KB
testcase_08 AC 39 ms
22,668 KB
testcase_09 AC 40 ms
22,972 KB
testcase_10 AC 39 ms
22,884 KB
testcase_11 AC 40 ms
22,424 KB
testcase_12 AC 80 ms
22,408 KB
testcase_13 AC 78 ms
22,556 KB
testcase_14 AC 36 ms
22,440 KB
testcase_15 AC 37 ms
22,404 KB
testcase_16 AC 37 ms
22,528 KB
testcase_17 AC 39 ms
22,260 KB
testcase_18 AC 37 ms
22,556 KB
testcase_19 AC 38 ms
23,024 KB
testcase_20 AC 43 ms
24,488 KB
testcase_21 AC 157 ms
24,924 KB
testcase_22 AC 157 ms
24,408 KB
testcase_23 AC 83 ms
22,804 KB
testcase_24 AC 60 ms
22,328 KB
testcase_25 AC 101 ms
24,608 KB
testcase_26 AC 100 ms
24,812 KB
testcase_27 AC 62 ms
22,412 KB
testcase_28 AC 54 ms
22,440 KB
testcase_29 AC 152 ms
22,832 KB
testcase_30 AC 151 ms
22,468 KB
testcase_31 AC 36 ms
22,508 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def ask(i, j):
    if aa[i][j] != -1: return aa[i][j]
    print(i+1, j+1, flush=True)
    ret = input()
    if ret == "-1": exit()
    aa[i][j] = ret == "Black"
    return aa[i][j]

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
n, m = map(int, input().split())
aa = [[-1]*n for _ in range(n)]
aa[0][0] = aa[n-1][n-1] = 1

cnt = 2
stack = [(0, 0)]
while stack and cnt < m:
    i, j = stack.pop()
    for di, dj in dij:
        ni, nj = i+di, j+dj
        if ni < 0 or nj < 0 or ni >= n or nj >= n: continue
        if aa[ni][nj] != -1: continue
        ret = ask(ni, nj)
        if ret:
            if (ni, nj) == (n-1, n-2) or (ni, nj) == (n-2, n-1):
                print("Yes", flush=True)
                exit()
            stack.append((ni, nj))
            cnt += 1
print("No")
0