結果
問題 | No.2646 Cycle Maze |
ユーザー |
|
提出日時 | 2025-06-28 13:51:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,960 ms / 2,500 ms |
コード長 | 1,510 bytes |
コンパイル時間 | 471 ms |
コンパイル使用メモリ | 82,752 KB |
実行使用メモリ | 153,496 KB |
最終ジャッジ日時 | 2025-06-28 13:51:22 |
合計ジャッジ時間 | 14,556 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 51 |
ソースコード
## https://yukicoder.me/problems/no/2646 from collections import deque DIRECTIONS = ((1, 0), (-1, 0), (0, 1), (0, -1), (0, 0)) def to_hw_index(W, h, w): return h * W + w def to_h_w(W, hw_index): return hw_index // W, hw_index % W 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): A.append(input()) dp = [False] * (H * W) dp[to_hw_index(W, Sh - 1, Sw - 1)] = True g_hw_index = to_hw_index(W, Gh - 1, Gw - 1) for t in range(T): new_dp = [False] * (H * W) for h in range(H): for w in range(W): hw_index = to_hw_index(W, h, w) if not dp[hw_index]: continue for dh, dw in DIRECTIONS: new_h = h + dh new_w = w + dw if 0 <= new_h < H and 0 <= new_w < W and t + 1 < T: new_hw_index = to_hw_index(W, new_h, new_w) if not new_dp[new_hw_index]: a = int(A[new_h][new_w]) if (a - t - 1) % (a + 1) != 0: new_dp[new_hw_index] = True if g_hw_index == new_hw_index: print("Yes") return dp = new_dp print("No") if __name__ == "__main__": main()