結果

問題 No.1588 Connection
ユーザー shakayamishakayami
提出日時 2021-07-08 23:27:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 306 ms / 2,000 ms
コード長 905 bytes
コンパイル時間 1,010 ms
コンパイル使用メモリ 87,100 KB
実行使用メモリ 99,076 KB
平均クエリ数 563.00
最終ジャッジ日時 2023-09-24 11:39:32
合計ジャッジ時間 7,640 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 127 ms
87,788 KB
testcase_01 AC 125 ms
87,372 KB
testcase_02 AC 119 ms
87,480 KB
testcase_03 AC 122 ms
86,952 KB
testcase_04 AC 117 ms
87,024 KB
testcase_05 AC 122 ms
87,984 KB
testcase_06 AC 124 ms
87,588 KB
testcase_07 AC 120 ms
87,628 KB
testcase_08 AC 123 ms
87,236 KB
testcase_09 AC 126 ms
87,496 KB
testcase_10 AC 123 ms
87,208 KB
testcase_11 AC 129 ms
87,600 KB
testcase_12 AC 202 ms
93,620 KB
testcase_13 AC 208 ms
94,508 KB
testcase_14 AC 131 ms
93,056 KB
testcase_15 AC 133 ms
92,044 KB
testcase_16 AC 124 ms
92,916 KB
testcase_17 AC 125 ms
92,356 KB
testcase_18 AC 133 ms
92,780 KB
testcase_19 AC 134 ms
92,084 KB
testcase_20 AC 130 ms
92,208 KB
testcase_21 AC 306 ms
99,076 KB
testcase_22 AC 303 ms
99,032 KB
testcase_23 AC 204 ms
93,536 KB
testcase_24 AC 168 ms
93,208 KB
testcase_25 AC 232 ms
98,096 KB
testcase_26 AC 214 ms
93,936 KB
testcase_27 AC 166 ms
92,948 KB
testcase_28 AC 170 ms
92,280 KB
testcase_29 AC 298 ms
95,484 KB
testcase_30 AC 292 ms
94,772 KB
testcase_31 AC 119 ms
87,508 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