結果
| 問題 |
No.1588 Connection
|
| コンテスト | |
| ユーザー |
tamato
|
| 提出日時 | 2021-07-08 22:54:10 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 277 ms / 2,000 ms |
| コード長 | 1,542 bytes |
| コンパイル時間 | 354 ms |
| コンパイル使用メモリ | 82,960 KB |
| 実行使用メモリ | 98,744 KB |
| 平均クエリ数 | 373.88 |
| 最終ジャッジ日時 | 2024-07-17 11:42:09 |
| 合計ジャッジ時間 | 5,296 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 31 |
ソースコード
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()
tamato