結果

問題 No.1588 Connection
ユーザー taiga0629kyopro
提出日時 2021-07-09 00:24:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 234 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 97,972 KB
平均クエリ数 562.59
最終ジャッジ日時 2024-07-17 12:48:48
合計ジャッジ時間 5,297 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m=map(int,input().split())
s=[[-1]*(n+1) for i in range(n+1)]
s[1][1]=1
s[n][n]=1
delta=[(1,0),(-1,0),(0,1),(0,-1)]
from _collections import deque


dp=[[10**18]*(n+1) for i in range(n+1)]
dp[1][1]=0
data=deque([(1,1)])
while data:
    i,j=data.popleft()
    for di,dj in delta:
        if not (1<=i+di<=n and 1<=j+dj<=n):continue
        x=i+di
        y=j+dj
        if s[x][y]==-1:
            print(x,y)
            t=input()
            if t[0]=="B":
                s[x][y]=1
            else:
                s[x][y]=0
        if s[x][y]==1 and dp[x][y]>dp[i][j]+1:
            dp[x][y]=dp[i][j]+1
            data.append((x,y))

print("Yes" if dp[n][n]<10**17 else "No")


0