結果

問題 No.1588 Connection
ユーザー 👑 KazunKazun
提出日時 2021-07-08 23:18:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 86,764 KB
実行使用メモリ 96,340 KB
平均クエリ数 481.78
最終ジャッジ日時 2023-09-24 11:36:31
合計ジャッジ時間 6,912 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
87,620 KB
testcase_01 AC 106 ms
87,372 KB
testcase_02 AC 107 ms
86,968 KB
testcase_03 AC 111 ms
86,932 KB
testcase_04 AC 106 ms
87,304 KB
testcase_05 AC 107 ms
86,956 KB
testcase_06 AC 108 ms
87,492 KB
testcase_07 AC 107 ms
87,452 KB
testcase_08 AC 115 ms
87,452 KB
testcase_09 AC 119 ms
86,996 KB
testcase_10 AC 119 ms
88,092 KB
testcase_11 AC 119 ms
87,656 KB
testcase_12 AC 193 ms
94,380 KB
testcase_13 AC 224 ms
94,036 KB
testcase_14 AC 112 ms
87,372 KB
testcase_15 AC 115 ms
87,040 KB
testcase_16 AC 116 ms
87,172 KB
testcase_17 AC 115 ms
87,292 KB
testcase_18 AC 114 ms
87,572 KB
testcase_19 AC 114 ms
87,308 KB
testcase_20 AC 119 ms
88,840 KB
testcase_21 AC 244 ms
96,340 KB
testcase_22 AC 274 ms
96,312 KB
testcase_23 AC 203 ms
94,124 KB
testcase_24 AC 160 ms
92,380 KB
testcase_25 AC 193 ms
95,232 KB
testcase_26 AC 204 ms
94,296 KB
testcase_27 AC 158 ms
92,244 KB
testcase_28 AC 143 ms
92,160 KB
testcase_29 AC 296 ms
93,740 KB
testcase_30 AC 259 ms
93,820 KB
testcase_31 AC 107 ms
87,364 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