結果
問題 |
No.467 隠されていたゲーム
|
ユーザー |
![]() |
提出日時 | 2025-06-12 21:15:13 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,078 bytes |
コンパイル時間 | 182 ms |
コンパイル使用メモリ | 81,932 KB |
実行使用メモリ | 288,028 KB |
最終ジャッジ日時 | 2025-06-12 21:16:25 |
合計ジャッジ時間 | 4,838 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 TLE * 1 -- * 18 |
ソースコード
import sys from collections import deque def main(): n = int(sys.stdin.readline()) d = list(map(int, sys.stdin.readline().split())) x, y = map(int, sys.stdin.readline().split()) target = (x, y) visited = {} q = deque() q.append((0, 0, 0)) visited[(0, 0)] = 0 while q: current_x, current_y, steps = q.popleft() if (current_x, current_y) == target: print(steps) return for di in d: max_diff = di for dx in range(-max_diff, max_diff + 1): for dy in range(-max_diff, max_diff + 1): if max(abs(dx), abs(dy)) != max_diff: continue new_x = current_x + dx new_y = current_y + dy if (new_x, new_y) not in visited or steps + 1 < visited[(new_x, new_y)]: visited[(new_x, new_y)] = steps + 1 q.append((new_x, new_y, steps + 1)) print(-1) if __name__ == "__main__": main()