#ABC472G. 级联网格 / Cascading Grid
级联网格 / Cascading Grid
Problem Statement
There is a grid with rows and columns. Each cell has one of the characters +, -, # written on it. Let denote the cell at the -th row from the top and the -th column from the left. The grid is given by length- strings : the -th character of is written on .
You can perform the following operation zero or more times:
- Choose one cell that is not
#. Change to#all cells that are "reachable from the chosen cell only by moving to an adjacent cell in the left, right, or down direction without passing through a cell that is#." Here, the chosen cell itself is included among the reachable cells.
Find the maximum possible value of the following value in the grid after the operations: the number of + cells minus the number of - cells.
Constraints
- is a string of length consisting of
+,-,#. - and are integers.
Input
The input is given from Standard Input in the following format:
Output
Output the answer.
2 3
+-+
--+
1
If you choose , all cells in row change to # (note that you cannot move upward). The remaining row has two cells of + and one cell of -, so the value is , and this is the maximum.
3 3
+--
-#-
#+#
1
If you choose , all cells except become #. Note that the chosen cell itself is included among the reachable cells, and that you cannot pass through a cell that is #.
5 7
++#--++
-+---+#
##++-++
--#-++-
+---#++
5
- Source: AtCoder ABC 472 G
相关
在下列比赛中: