#P2337. [SCOI2012] 喵星人的入侵
[SCOI2012] 喵星人的入侵
Description
a180285 was luckily chosen as an exchange student from Earth to the Meow Planet—actually as an agent to investigate whether the Meowians intend to invade Earth. The Meowians do plan to invade Earth! After obtaining the exact information from a180285, the Earth task force decided to devise an anti-invasion plan.
A mandatory route from the Meow Planet to Earth can be viewed as an grid. The Meowians will start from position on the map, and their destination is Earth’s entrance . To resist the Meowian invasion, the Earth Defense Team plans to place some turrets on grid cells (at most turrets). A turret attacks in all directions (the directions are: east, south, west, north, northeast, northwest, southeast, southwest) (as shown in the figure below, a turret in the center cell can attack the eight surrounding cells). In addition, the Earth Defense Team can place an unlimited number of obstacles on the map so that the Meowians cannot pass through cells with obstacles.

The figure shows an example on a map, where denotes a turret and denotes an obstacle. Cells containing a turret or an obstacle are impassable to the Meowians. On this map, the damage taken by the Meowians when moving from to is as follows:
- At , the damage is (the turrets at and can attack ).
- At the empty cell , the damage is (simultaneously attacked by the turrets , , and ).
- At , the damage is (the turrets at and can attack ).
Therefore, the total damage is .
As a member of the Earth Defense Team, please arrange the placement so that the Meowians take the maximum possible damage. Note that if there are multiple paths from to , the Meowians will choose the one with the minimal damage.
Input Format
The first line contains three integers , denoting the number of rows and columns of the map, and the maximum number of turrets that can be placed.
The next lines each contain characters: denotes an existing obstacle on the map, denotes an empty cell, denotes the start, and denotes the destination. It is guaranteed that in the original map there exists a path from to .
Output Format
Output the maximum damage the Meowians will take under an optimal placement, assuming they take the optimal route.
Note that after the placement, you must still ensure that the Meowians can reach the destination from the start along at least one path; otherwise, they will organize an even larger-scale invasion.
3 3 1
S.T
...
...
7
Hint
Sample Explanation
One optimal layout for the sample is as follows:
S#T
.X.
...
Constraints
- For of the testdata, .
- For of the testdata, , , , and a path from to always exists.
Translated by ChatGPT 5
京公网安备 11011102002149号