結果

問題 No.1588 Connection
ユーザー 👑 KazunKazun
提出日時 2021-07-08 23:18:50
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 314 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 263 ms
使用メモリ 102,288 KB
平均クエリ数 481.78
最終ジャッジ日時 2023-02-15 01:09:47
合計ジャッジ時間 7,231 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 107 ms
91,744 KB
testcase_01 AC 105 ms
91,516 KB
testcase_02 AC 106 ms
91,612 KB
testcase_03 AC 109 ms
91,568 KB
testcase_04 AC 111 ms
91,180 KB
testcase_05 AC 110 ms
91,236 KB
testcase_06 AC 111 ms
91,404 KB
testcase_07 AC 107 ms
91,584 KB
testcase_08 AC 113 ms
91,536 KB
testcase_09 AC 115 ms
91,116 KB
testcase_10 AC 116 ms
91,776 KB
testcase_11 AC 116 ms
91,528 KB
testcase_12 AC 208 ms
97,664 KB
testcase_13 AC 226 ms
98,556 KB
testcase_14 AC 106 ms
91,192 KB
testcase_15 AC 110 ms
91,668 KB
testcase_16 AC 107 ms
90,976 KB
testcase_17 AC 109 ms
91,912 KB
testcase_18 AC 107 ms
91,168 KB
testcase_19 AC 107 ms
91,432 KB
testcase_20 AC 109 ms
91,468 KB
testcase_21 AC 264 ms
102,288 KB
testcase_22 AC 295 ms
102,276 KB
testcase_23 AC 211 ms
98,048 KB
testcase_24 AC 162 ms
96,128 KB
testcase_25 AC 209 ms
101,596 KB
testcase_26 AC 222 ms
100,516 KB
testcase_27 AC 160 ms
96,496 KB
testcase_28 AC 147 ms
96,480 KB
testcase_29 AC 310 ms
99,332 KB
testcase_30 AC 314 ms
98,184 KB
testcase_31 AC 107 ms
91,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def question(a,b):
    print(a,b,flush=True)
    ans=input()

    if ans[0]=="B":
        return 1
    elif ans[0]=="W":
        return 0
    else:
        exit()

def answer(ans):
    exit(print(ans,flush=True))
#=================================================
from collections import deque
N,M=map(int,input().split())

# 自明な否定
if 2*N-1>M:
    answer("No")

X=[[-1]*(N+1) for _ in range(N+1)]
X[1][1]=X[N][N]=1
Remain=M-2

Q=deque([(1,1)])
T=[(1,0),(-1,0),(0,1),(0,-1)]

while Q:
    x,y=Q.popleft()

    if Remain==0:
        break

    for a,b in T:
        p=x+a; q=y+b
        if 1<=p<=N and 1<=q<=N and X[p][q]==-1 and (N-p)+(N-q)<=Remain:
                X[p][q]=quest=question(p,q)

                if quest:
                    if (N-p)+(N-q)==1:
                        break

                    Q.append((p,q))
                    Remain-=1

F=[[0]*(N+1) for _ in range(N+1)]; F[1][1]=1
Q=deque([(1,1)])
while Q:
    x,y=Q.popleft()
    for a,b in T:
        p=x+a; q=y+b
        if 1<=p<=N and 1<=q<=N and X[p][q]==1 and F[p][q]==0:
            F[p][q]=1
            Q.append((p,q))

answer("Yes" if F[N][N] else "No")
0