#Lutece1162. Just a Maze
Just a Maze
Migrated from Lutece 1162 Just a Maze
All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.
Description
Here is a maze with N × M room.
You start from the room () and want to go to the room located at (). However, there are many traps and monsters in this maze.
There are 4 types of rooms:
- Blank->('.'). which has nothing.
- Rock->('#'). which you can not enter it.
- Trap->('a' - 'z'), which once you enter it, you will suffer (Trap-'a'+1) damage(s). After you leave,the trap will reset so it can be triggered next time.
- Monster->('A' - 'Z'). If you go into a monster room or any room adjacent to a monster room, the monster will immediately rush up to you and fight with you. You will kill it, but you will get hurt too, suffering (Monster-'A'+1) damage(s). And the monster will not revive.
Two rooms are adjacent if and only if they share an edge. You can take 1 step to go from a room to another adjacent room.
The safest path is a lowest total damage path. Among all safest path,find the path with lowest steps.
Input
The first line contains two integers N and M ().
The second line contains 4 integers ( and ).
For the next lines, each line contains characters indicating the map of maze. Each type of room is marked as:
- Blank->('.')
- Rock->('#')
- Trap: from 'a' - 'z'
- Monster: from 'A' - 'Z'
The damage you suffer from the trap 'a' is 1,'b' is 2..and so on.
The damage you suffer from the monster 'A' is 1... and 'Z' is 26.
The room () and () are always blank rooms and will not be adjacent to any monster room.
Output
Output the lowest total damage and the lowest steps in all safest path.
Samples
3 5
1 1 3 5
..b..
.zC#.
..a..
4 6
Resources
2015 UESTC ACM Summer Training Team Selection (4)