Do You Have a Problem with Insung??
InterviewTime limit1sMemory limit512 MB
On an H by W grid with obstacles of varying height, decide if Insung can reach the goal, given that each move costs 1 strength and climbing to a higher cell costs extra strength equal to the height difference.
- Level
Medium5 of 10
- Topics
- BFS, Graph, Simulation, Implementation
- Solved
- No attempts yet
Problem
Insung joined the Insat special course to become popular. On the first day of training, Insung must reach the goal in a treacherous maze. If he fails to get through the maze within the time limit, Instructor Myeonggi will curse at him, so Insung tries his best to get through the maze.
The maze is a grid of width and height , and Insung can move one cell up, down, left, or right on the grid per move. Each time a move is completed, Insung's remaining strength decreases by 1, and once the remaining strength becomes 0 or less, he can no longer move.
Each cell of the maze may contain an obstacle, and each obstacle has a height. Every location without an obstacle has height 0. When Insung moves, if the height of the destination is lower than the height of his current location, he can move with no restriction. When moving to a higher place, he can jump, and the height he must jump is (height of the destination - height of the current location). If his remaining strength is greater than or equal to the height he must jump, he can move; otherwise, he cannot move.
Can Insung overcome his physical limits, reach the goal safely, and avoid being cursed at by Instructor Myeonggi?
Input
The first line gives the number of test cases . Each test case is given as follows.
The first line gives the maze's height , width , number of obstacles , initial strength , the start coordinates (row), (column), and the goal coordinates (row), (column).
From the second line, lines give the coordinates (row), (column) and height of each obstacle. All obstacles are at distinct locations.
Output
For each of the lines, print "잘했어!!" if Insung can reach the goal, and "인성 문제있어??" if he cannot reach the goal.
Constraints
- , is an integer.
- , is an integer.
- The start and goal positions have no obstacle.