#C4383. Robot Route Feasibility
Robot Route Feasibility
Robot Route Feasibility
You are given a city map represented as an n x m grid. The grid consists of several types of cells:
- S: the starting point (the charging station).
- C: collection points that the robot must visit.
- O: obstacles that cannot be traversed.
- W: water cells that cost extra battery to cross (2 battery units per move).
- .: open cells that cost 1 battery unit per move.
The robot starts at cell S
and must visit all collection points C
. The challenge is to determine whether there exists a route which allows the robot to visit every collection point (and implicitly return to S
, as the starting point is part of the visited set) within the provided battery capacity. Note that while the description mentions returning to the charging station, the problem is simplified to checking whether all required points are reachable under the battery constraint.
Assume the robot may move in the four cardinal directions (up, down, left, right), and each move consumes battery as stated above.
inputFormat
The input is read from standard input and has the following format:
- The first line contains three space-separated integers:
n
(number of rows),m
(number of columns), andbattery
(the maximum battery capacity). - The next
n
lines each contain a string of lengthm
, representing the city map.
outputFormat
Output a single line to standard output containing either possible
if the robot can visit all collection points within the battery limit, or impossible
otherwise.
4 5 20
S..CO
.O.W.
..WC.
...C
possible
</p>