結果

問題 No.1588 Connection
ユーザー mkawa2mkawa2
提出日時 2021-07-08 22:55:49
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 778 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 10,972 KB
実行使用メモリ 26,484 KB
平均クエリ数 536.75
最終ジャッジ日時 2023-09-24 10:51:05
合計ジャッジ時間 3,894 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
23,964 KB
testcase_01 AC 41 ms
24,452 KB
testcase_02 AC 38 ms
24,180 KB
testcase_03 AC 41 ms
23,660 KB
testcase_04 AC 39 ms
24,516 KB
testcase_05 AC 39 ms
23,864 KB
testcase_06 AC 40 ms
24,016 KB
testcase_07 AC 38 ms
23,952 KB
testcase_08 AC 42 ms
23,900 KB
testcase_09 AC 42 ms
24,548 KB
testcase_10 AC 42 ms
24,308 KB
testcase_11 AC 42 ms
23,764 KB
testcase_12 AC 80 ms
23,764 KB
testcase_13 AC 78 ms
24,248 KB
testcase_14 AC 38 ms
24,332 KB
testcase_15 AC 40 ms
24,464 KB
testcase_16 AC 39 ms
23,876 KB
testcase_17 AC 39 ms
23,592 KB
testcase_18 AC 40 ms
24,372 KB
testcase_19 AC 40 ms
24,608 KB
testcase_20 AC 45 ms
26,352 KB
testcase_21 AC 151 ms
25,980 KB
testcase_22 AC 153 ms
25,804 KB
testcase_23 AC 83 ms
24,588 KB
testcase_24 AC 61 ms
24,220 KB
testcase_25 AC 99 ms
26,336 KB
testcase_26 AC 96 ms
26,484 KB
testcase_27 AC 62 ms
24,820 KB
testcase_28 AC 55 ms
24,532 KB
testcase_29 AC 145 ms
23,912 KB
testcase_30 AC 144 ms
23,964 KB
testcase_31 AC 39 ms
23,724 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