#P2337. [SCOI2012] 喵星人的入侵

    ID: 1313 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>字符串2012四川各省省选后缀数组,SA构造

[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 n×mn\times m grid. The Meowians will start from position SS on the map, and their destination is Earth’s entrance TT. To resist the Meowian invasion, the Earth Defense Team plans to place some turrets on grid cells (at most KK turrets). A turret attacks in all 88 directions (the 88 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 3×33\times 3 map, where X\tt X denotes a turret and #\tt \# 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 SS to TT is as follows:

  • At S(1,0)S(1, 0), the damage is 22 (the turrets at (0,0)(0,0) and (2,1)(2, 1) can attack SS).
  • At the empty cell (1,1)(1,1), the damage is 33 (simultaneously attacked by the turrets (0,0)(0,0), (0,2)(0,2), and (2,1)(2, 1)).
  • At T(1,2)T(1,2), the damage is 22 (the turrets at (0,2)(0,2) and (2,1)(2, 1) can attack TT).

Therefore, the total damage is 2+3+2=72+3+2=7.

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 SS to TT, the Meowians will choose the one with the minimal damage.

Input Format

The first line contains three integers n,m,Kn,m,K, denoting the number of rows and columns of the map, and the maximum number of turrets that can be placed.

The next nn lines each contain mm characters: #\tt \# denotes an existing obstacle on the map, .\tt . denotes an empty cell, S\tt S denotes the start, and T\tt T denotes the destination. It is guaranteed that in the original map there exists a path from SS to TT.

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 TT from the start SS 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 30%30\% of the testdata, 1n,m61\le n,m\leq 6.
  • For 100%100\% of the testdata, min(n,m)6\min(n,m)\le 6, max(n,m)20\max(n,m)\le 20, 1K151\le K\le 15, and a path from SS to TT always exists.

Translated by ChatGPT 5