PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#FW0000094. Kho báu của cướp biển Râu Đen (Blackbeard the Pirate)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Kho báu của cướp biển Râu Đen (Blackbeard the Pirate)
Blackbeard the Pirate
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
An island map contains landing point @, treasures !, water ~, palm trees #, hostile camps *, and sand .. Camps and all eight neighboring cells are forbidden. Movement uses four cardinal directions with unit cost. Collect all treasures and return to @ in minimum time; print -1 if impossible.
Input
First , then map rows of width . Let be the number of ! treasure cells.
Output
Print minimum hours or -1.
Subtasks
-
Subtask 1 (40 points): . All input-format and graph conditions above apply.
-
Subtask 2 (60 points): . All input-format and graph conditions above apply.
Examples
Input
2 2
@!
..
Output
2
Explanation
Start at @ in row 1, column 1, move right to collect !, then return one step left. Total two moves.