Pyroclastic Flow
Time limit1sMemory limit128 MB
On an M by N elevation grid with timed volcano eruptions whose flow spreads Manhattan style, find the reachable cell of highest elevation and the earliest arrival time there.
- Level
Medium7 of 10
- Topics
- Shortest path, Heap, Graph, Implementation
- Solved
- No attempts yet
Problem
Volcanologist Yun Jaesang went to explore a volcanic island, and soon received an urgent notice that the volcanoes on the island would begin erupting, along with the eruption time of each volcano.
The island is represented as a matrix with M rows and N columns. Let the location of a volcano be (x, y) and the time it starts erupting be t. At time t+δ, every cell (u, v) with δ ≥ |u-x|+|v-y| is struck by pyroclastic flow, regardless of elevation. Jaesang wants to escape quickly.
- Jaesang starts at row X, column Y.
- Jaesang can move one cell up, down, left, or right per unit time.
- Jaesang cannot go to a cell containing a volcano or a cell covered by pyroclastic flow.
Jaesang wants to flee to as high a place as possible while avoiding the pyroclastic flow, and to arrive as quickly as possible. Find the highest elevation Jaesang can reach while avoiding the pyroclastic flow, and the minimum time it takes to reach that elevation.
Input
The first line contains the integers M, N, and V separated by spaces. (1 ≤ M, N ≤ 100, 1 ≤ V ≤ min(5,000, M×N))
The next line contains X and Y separated by a space. (1 ≤ X ≤ M, 1 ≤ Y ≤ N)
From the next line, M lines each contain N space-separated numbers. The value at row i, column j is the elevation hij of cell (i, j). (0 ≤ hij ≤ 10,000)
From the next line, V lines follow. The i-th line contains xi, yi, ti separated by spaces. These numbers mean the location (xi, yi) of the i-th volcano and its eruption time ti. (1 ≤ xi ≤ M, 1 ≤ yi ≤ N, 0 ≤ ti ≤ 200)
All location, time, and elevation values are integers. No input places a volcano at row X, column Y.
Output
Print the highest elevation Jaesang can reach and the minimum time to reach that elevation, separated by a space.