結果

問題 No.1588 Connection
ユーザー shakayamishakayami
提出日時 2021-07-08 23:27:19
言語 PyPy3
(7.3.8)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 545 ms
使用メモリ 103,292 KB
平均クエリ数 563.00
最終ジャッジ日時 2023-02-15 01:13:28
合計ジャッジ時間 7,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 105 ms
90,984 KB
testcase_01 AC 106 ms
90,612 KB
testcase_02 AC 109 ms
91,648 KB
testcase_03 AC 108 ms
91,224 KB
testcase_04 AC 108 ms
90,928 KB
testcase_05 AC 108 ms
91,772 KB
testcase_06 AC 109 ms
90,948 KB
testcase_07 AC 107 ms
91,340 KB
testcase_08 AC 114 ms
91,512 KB
testcase_09 AC 116 ms
91,184 KB
testcase_10 AC 115 ms
91,656 KB
testcase_11 AC 115 ms
91,388 KB
testcase_12 AC 198 ms
97,712 KB
testcase_13 AC 219 ms
97,788 KB
testcase_14 AC 114 ms
95,652 KB
testcase_15 AC 114 ms
95,680 KB
testcase_16 AC 111 ms
96,032 KB
testcase_17 AC 113 ms
95,812 KB
testcase_18 AC 112 ms
95,700 KB
testcase_19 AC 113 ms
95,656 KB
testcase_20 AC 116 ms
95,560 KB
testcase_21 AC 311 ms
103,084 KB
testcase_22 AC 307 ms
102,720 KB
testcase_23 AC 214 ms
98,868 KB
testcase_24 AC 160 ms
96,460 KB
testcase_25 AC 238 ms
103,292 KB
testcase_26 AC 235 ms
101,788 KB
testcase_27 AC 159 ms
96,888 KB
testcase_28 AC 144 ms
95,772 KB
testcase_29 AC 291 ms
99,028 KB
testcase_30 AC 310 ms
99,680 KB
testcase_31 AC 105 ms
90,972 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
N,M=map(int,input().split())
dist=[[-1 for j in range(N)]for i in range(N)]
color=[[None for j in range(N)]for i in range(N)]
color[0][0]=1
def reachable(i,j):
    if color[i][j]==0:
        return False
    elif color[i][j]==1:
        return True
    else:
        print("{0} {1}".format(i+1,j+1),flush=True)
        T=input()
        if T=="Black":
            color[i][j]=1
            return True
        elif T=="White":
            color[i][j]=0
            return False
q=deque([(0,0)])
dist[0][0]=0
dx=[0,1,0,-1]
dy=[1,0,-1,0]
while(q):
    x,y=q.popleft()
    for k in range(4):
        nx=x+dx[k]
        ny=y+dy[k]
        if 0<=nx<N and 0<=ny<N:
            if dist[nx][ny]==-1:
                if reachable(nx,ny):
                    dist[nx][ny]=dist[x][y]+1
                    q.append((nx,ny))
if dist[N-1][N-1]==-1:
    print("No")
else:
    print("Yes")
0