Knight of the Tarot Cards
Time limit10sMemory limit512 MB
Find the minimum total price of tarot cards the knight must buy to reach (0, 0), where each card's values unlock new knight jumps.
- Level
Hard8 of 10
- Topics
- Graph, Shortest path, Greedy, Math
- Solved
- No attempts yet
Problem
Consider an infinite chessboard and a special knight whose move types can change given powerups. The knight is trying to reach square .
Some squares of the infinite chessboard have tarot cards on them. If the knight lands on a position with a tarot card on it, the knight can buy that card at that position. Each tarot card has a price and two integer values written on it. The tarot card with values and allows the knight to make these relative jumps:
, , , , , , ,
The knight keeps every card it buys and can make relative moves from any card it owns, any number of times. The knight pays only when it obtains a card. Jumps cost nothing. For example, if the knight buys a card with 3 and 2 and another card with 8 and 4, it may jump by , then by , and later by . The knight cannot make a jump until it arrives at a square with a tarot card showing and and buys that card.
Given the positions of the tarot cards and their prices, find the least amount the knight must pay to reach .
Input
Each test case begins with a line containing a single integer (), the number of tarot cards on the chessboard.
Each of the next lines describes a tarot card with five space-separated integers:
Here and . The pair is the location of the card, and are its offset values, and is its price. The first tarot card is the knight's initial position. Multiple tarot cards may exist at the same location. The knight must have a tarot card to move.
Output
Output a single integer, the minimum cost for the knight to reach . Output if the goal cannot be reached.