A Man with a Plan
Statement
Goal
Art by Florent Llamas:
Input
First line: W, H and N, three integers, respectively the width and the height of the realm, and the number of points of interest existing in the realm.
Second line: O, a string, the objective of the king's quest.
Next H lines: A string of length W with each char representing a piece of land of the realm, among:
-G for a grassland,
-W for a water point,
-M for a mountain,
-S for a swamp,
-R for a ravine,
-I for a point of interest.
Next N lines: k, x and y, a string and two integers, respectively the kind and the coordinates of a point of interest. With k among:
-HOUSE ,
-CASTLE ,
-BLACKSMITH ,
-STABLE ,
-WIZARD ,
-PRINCESS ,
-DRAGON ,
-TREASURE .
Second line: O, a string, the objective of the king's quest.
Next H lines: A string of length W with each char representing a piece of land of the realm, among:
-
-
-
-
-
-
Next N lines: k, x and y, a string and two integers, respectively the kind and the coordinates of a point of interest. With k among:
-
-
-
-
-
-
-
-
Output
An integer D, the minimum number of days that your quest will take.
Constraints
The (0, 0) coordinates correspond to the top-left corner of the realm.
Each piece of land is directly connected to its eight neighbors.
The wizard uses Manhattan distance.
3 <= W, H <= 20
3 <= N <= 8
0 <= x < W
0 <= y < H
0 < D < 100
Each piece of land is directly connected to its eight neighbors.
The wizard uses Manhattan distance.
3 <= W, H <= 20
3 <= N <= 8
0 <= x < W
0 <= y < H
0 < D < 100
Example
Input
5 5 3 PRINCESS GGGGI GGGGG GGIGG GGGGG IGGGG HOUSE 0 4 CASTLE 4 0 PRINCESS 2 2
Output
9
Tags
Pathfinding, Reading the statement
Difficulty
Hard
Test cases
Run to the Hills Test
Input
5 5 3
PRINCESS
GGGGI
GGGGG
GGIGG
GGGGG
IGGGG
HOUSE 0 4
CASTLE 4 0
PRINCESS 2 2
Output
9
Run to the Hills Validator
Input
5 5 3
PRINCESS
IGGGI
GGGGG
GGGGG
GGGGG
GGGGI
HOUSE 4 4
CASTLE 0 0
PRINCESS 4 0
Output
17
Hall of the Mountain King Test
Input
5 5 4
TREASURE
IMMMI
MMMMM
GGIMM
GGGGG
IGGGG
HOUSE 0 4
CASTLE 4 0
STABLE 2 2
TREASURE 0 0
Output
25
Hall of the Mountain King Validator
Input
5 5 4
TREASURE
MMMMI
MMMMM
IGIMM
GGGGG
GGGGI
HOUSE 4 4
CASTLE 4 0
STABLE 2 2
TREASURE 0 2
Output
21
The River Test
Input
5 5 4
DRAGON
IGGGI
GGGGG
WWWWW
GGGGG
IIGGG
HOUSE 0 4
CASTLE 0 0
BLACKSMITH 1 4
DRAGON 4 0
Output
17
The River Validator
Input
5 5 4
DRAGON
IIGGG
GGGGG
WWWWW
GGGGG
GGGII
HOUSE 4 4
CASTLE 1 0
BLACKSMITH 3 4
DRAGON 0 0
Output
11
Rise of the Chaos Wizards Test
Input
5 5 4
TREASURE
GGGGI
IGGGG
RRRRR
IGGGG
GGGGI
HOUSE 4 4
CASTLE 4 0
WIZARD 0 3
TREASURE 0 1
Output
18
Rise of the Chaos Wizards Validator
Input
5 5 4
TREASURE
GGGGI
GIGGG
RRRRR
IGGGG
GGGGI
HOUSE 4 4
CASTLE 4 0
WIZARD 0 3
TREASURE 1 1
Output
16
Iron Man Test
Input
5 5 5
PRINCESS
RRIRR
RRIRR
RRGRR
GGGIG
IGGGI
HOUSE 0 4
CASTLE 4 4
BLACKSMITH 3 3
DRAGON 2 1
PRINCESS 2 0
Output
16
Iron Man Validator
Input
5 5 5
PRINCESS
RRIRR
RRIRR
RRGRR
GIGIG
GGGGI
HOUSE 1 3
CASTLE 4 4
BLACKSMITH 3 3
DRAGON 2 1
PRINCESS 2 0
Output
14
To Hell and Back Test
Input
5 6 6
TREASURE
ISSSS
RRRSS
RRIRR
RGGGR
GGGGI
IGIIG
HOUSE 0 5
CASTLE 4 4
STABLE 2 5
BLACKSMITH 3 5
DRAGON 2 2
TREASURE 0 0
Output
31
To Hell and Back Validator
Input
5 6 6
TREASURE
ISSSS
RSSSS
RRIRR
RGGGR
GGGGI
IGIIG
HOUSE 0 5
CASTLE 4 4
STABLE 2 5
BLACKSMITH 3 5
DRAGON 2 2
TREASURE 0 0
Output
19
Thunderhorse Test
Input
14 14 5
DRAGON
WWRRRMMMMMMMMM
RWWWRIMMMMMMMW
RRRWWGGMMMIGWW
MMRRWGGGGGGWWW
MMSSWGGGIGWWWW
MMSSWWWGGGGWWW
MSSSSSWWGGGGWW
MSSSSSSWWIGGWW
MMISSSSSSWWWWW
MMMSSSSSSSGWWW
MMMGGGGGSGGGWW
MMGGWWWGGGWWWW
MWWWWWWWWWWWWW
WWWWWWWWWWWWWW
HOUSE 10 2
CASTLE 5 1
STABLE 8 4
BLACKSMITH 9 7
DRAGON 2 8
Output
27
Thunderhorse Validator
Input
14 14 5
DRAGON
WWRRRMMMMMMMMM
RWWWRIMMMMMMMW
RRRWWGGMMMIGWW
MMRRWGGGGGGWWW
MMSSWGGGIGWWWW
MMSSWWWGGGGWWW
MSSSSSWWGGGGWW
MSSSSSSWWIGGWW
MMSSSSSSSWWWWW
MMMSSSISSSGWWW
MMMGGGGGSGGGWW
MMGGWWWGGGWWWW
MWWWWWWWWWWWWW
WWWWWWWWWWWWWW
HOUSE 10 2
CASTLE 5 1
STABLE 8 4
BLACKSMITH 9 7
DRAGON 6 9
Output
23
Carry On Test
Input
10 10 7
TREASURE
IIMMRRSISS
RRRRMRSSSS
RMMMRRSSSS
MRRRRMSSSS
GMMMMSSGGS
IGWWWWWWGS
GWWWWWWWWG
GWWIIWWWWG
GGWGWWWWGG
GIGGGGGGGG
HOUSE 1 9
CASTLE 3 7
BLACKSMITH 4 7
STABLE 0 5
WIZARD 7 0
DRAGON 1 0
TREASURE 0 0
Output
71
Carry On Validator
Input
10 10 7
TREASURE
IIMMRRSISS
RRRRMRSSSS
RMMMRRSSSS
MRRRRMSSSS
GMMMMSSGGS
GGWWWWWWGS
IWWWWWWWWG
GWWIIWWWWG
GGWGWWWWGG
GIGGGGGGGG
HOUSE 1 9
CASTLE 3 7
BLACKSMITH 4 7
STABLE 0 6
WIZARD 7 0
DRAGON 1 0
TREASURE 0 0
Output
72
Solution language
Solution
Stub generator input