結果

問題 No.2646 Cycle Maze
ユーザー LyricalMaestro
提出日時 2025-06-28 13:35:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,121 bytes
コンパイル時間 402 ms
コンパイル使用メモリ 82,100 KB
実行使用メモリ 231,996 KB
最終ジャッジ日時 2025-06-28 13:36:00
合計ジャッジ時間 7,755 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 34 WA * 5 TLE * 5 -- * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

## https://yukicoder.me/problems/no/2646

from collections import deque

def main():
    H, W, T = map(int, input().split())
    Sh, Sw = map(int, input().split())
    Gh, Gw = map(int, input().split())
    A = []
    for _ in range(H):
        row = input()
        A.append([int(r) for r in row])
    
    dp = [[[False] * T for _ in range(W)] for _ in range(H)]
    dp[Sh - 1][Sw - 1][0] = True

    queue = deque()
    queue.append((Sh - 1, Sw - 1, 0))
    while len(queue) > 0:
        h, w, t = queue.popleft()

        for dh, dw in ((1, 0), (-1, 0), (0, 1), (0, -1), (0, 0)):
            new_h = h + dh
            new_w = w + dw
            if  0 <= new_h < H and 0 <= new_w < W and t + 1 < T:
                if not dp[new_h][new_w][t + 1]:
                    a = A[new_h][new_w]
                    if (a - t) % (a + 1) != 0:
                        dp[new_h][new_w][t + 1] = True
                        queue.append((new_h, new_w, t + 1))
    
    for t in range(T):
        if dp[Gh - 1][Gw - 1][t]:
            print("Yes")
            return
    print("No")









if __name__ == "__main__":
    main()
0