結果

問題 No.1588 Connection
ユーザー tamatotamato
提出日時 2021-07-08 22:54:10
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 333 ms / 2,000 ms
コード長 1,542 bytes
コンパイル時間 265 ms
使用メモリ 102,268 KB
平均クエリ数 373.88
最終ジャッジ日時 2023-02-15 00:09:18
合計ジャッジ時間 7,364 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 112 ms
90,920 KB
testcase_01 AC 110 ms
91,188 KB
testcase_02 AC 112 ms
90,544 KB
testcase_03 AC 112 ms
90,988 KB
testcase_04 AC 114 ms
91,276 KB
testcase_05 AC 111 ms
90,744 KB
testcase_06 AC 115 ms
91,088 KB
testcase_07 AC 111 ms
90,824 KB
testcase_08 AC 121 ms
90,720 KB
testcase_09 AC 113 ms
91,028 KB
testcase_10 AC 114 ms
90,768 KB
testcase_11 AC 114 ms
90,964 KB
testcase_12 AC 120 ms
94,988 KB
testcase_13 AC 124 ms
95,620 KB
testcase_14 AC 114 ms
90,636 KB
testcase_15 AC 117 ms
90,676 KB
testcase_16 AC 112 ms
91,380 KB
testcase_17 AC 112 ms
90,680 KB
testcase_18 AC 113 ms
90,752 KB
testcase_19 AC 114 ms
91,028 KB
testcase_20 AC 113 ms
91,236 KB
testcase_21 AC 276 ms
101,996 KB
testcase_22 AC 284 ms
101,824 KB
testcase_23 AC 194 ms
98,160 KB
testcase_24 AC 149 ms
95,256 KB
testcase_25 AC 234 ms
101,672 KB
testcase_26 AC 263 ms
102,268 KB
testcase_27 AC 176 ms
97,460 KB
testcase_28 AC 156 ms
95,624 KB
testcase_29 AC 317 ms
98,232 KB
testcase_30 AC 333 ms
98,136 KB
testcase_31 AC 110 ms
90,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from heapq import heappush, heappop
    input = sys.stdin.readline

    def ask(h, w):
        print(h, w)
        sys.stdout.flush()
        return input().rstrip('\n')

    def ask2(h, w):
        if G[h-1][w-1]:
            return "Black"
        else:
            return "White"

    N, M = map(int, input().split())
    G = [[0] * N for _ in range(N)]
    """
    for _ in range(M):
        a, b = map(int, input().split())
        G[a-1][b-1] = 1
    """
    H = W = N
    Q = 3000
    pq = []
    heappush(pq, (N*2-3, 1))
    heappush(pq, (N*2-3, W))
    seen = [[0] * N for _ in range(N)]
    d = [(0, 1), (0, -1), (1, 0), (-1, 0)]
    M -= 2
    while Q:
        if pq:
            _, hw = heappop(pq)
        else:
            break
        h, w = hw // W, hw % W
        if seen[h][w]:
            continue
        seen[h][w] = 1
        T = ask(h+1, w+1)
        Q -= 1
        if T == -1:
            exit()
        elif T == "Black":
            M -= 1
            for dh, dw in d:
                h_new, w_new = h+dh, w+dw
                if 0 <= h_new < H and 0 <= w_new < W:
                    if h_new == H-1 and w_new == W-1:
                        print("Yes")
                        sys.stdout.flush()
                        exit()
                    p = H-1 - h_new + W-1 - w_new
                    if p - 1 <= M:
                        heappush(pq, (H-1 - h_new + W-1 - w_new, h_new*W+w_new))
    print("No")


if __name__ == '__main__':
    main()
0