結果

問題 No.2646 Cycle Maze
ユーザー nikoro256
提出日時 2024-02-25 19:00:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,684 ms / 2,500 ms
コード長 1,057 bytes
コンパイル時間 628 ms
コンパイル使用メモリ 82,488 KB
実行使用メモリ 158,200 KB
最終ジャッジ日時 2024-09-29 11:06:32
合計ジャッジ時間 13,859 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
def bfs(s):
    dq=deque()
    dq.append([s,0])
    high=[10**9 for _ in range(N)]
    high[s]=0
    while len(dq)!=0:
        p,h=dq.popleft()
        for e in edge[p]:
            if  high[e]==10**9:
                dq.append([e,h+1])
                high[e]=h+1
    return high

H,W,T=map(int,input().split())
Sy,Sx=map(int,input().split())
Gy,Gx=map(int,input().split())
A=[]
for _ in range(H):
    tmp=input()
    A.append([int(tmp[i]) for i in range(W)])
dp=[[False]*W for _ in range(H)]
dp[Sy-1][Sx-1]=True
for i in range(T-1):
    ndp=[[False]*W for _ in range(H)]
    for j in range(H):
        for k in range(W):
            if dp[j][k]:
                for d1,d2 in [[1,0],[0,1],[-1,0],[0,-1],[0,0]]:
                    x=j+d1
                    y=k+d2
                    if 0<=x<H and 0<=y<W and (A[x][y]-i-1)%(A[x][y]+1)!=0:
                        ndp[x][y]=True
                        if x==Gy-1 and y==Gx-1:
                            print('Yes')
                            exit(0)
    dp=ndp
print('No')
0