結果

問題 No.2646 Cycle Maze
ユーザー LyricalMaestro
提出日時 2025-06-28 13:37:57
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,125 bytes
コンパイル時間 368 ms
コンパイル使用メモリ 82,352 KB
実行使用メモリ 281,832 KB
最終ジャッジ日時 2025-06-28 13:38:28
合計ジャッジ時間 30,116 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 39 TLE * 4 -- * 8
権限があれば一括ダウンロードができます

ソースコード

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 - 1) % (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