AT_abc475_f.Rectangle Filling
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a grid with H rows and W columns. Let the cell at the i-th row from the top and j-th column from the left be denoted as cell (i,j).
Each cell of the grid is painted white or black: cell (i,j) is white if the j-th character of Si is ., and black if it is #.
You can perform the following operation at most once.
- Choose a rectangular region, and paint all cells within that region black. More formally, choose integers h1,h2,w1,w2 satisfying 1≤h1≤h2≤H and 1≤w1≤w2≤W, and paint cell (h,w) black for every pair of integers (h,w) satisfying h1≤h≤h2 and w1≤w≤w2.
Find the number of possible states of the grid that can be obtained. Here, two states of the grid are considered different if there exists a pair of integers (i,j) satisfying 1≤i≤H and 1≤j≤W such that cell (i,j) is painted white in one state and painted black in the other state.
有一个 H 行 W 列的网格。记从上往下第 i 行、从左往右第 j 列的格子为格子 (i,j)。
网格中的每个格子被涂成白色或黑色:若字符串 Si 的第 j 个字符为 .,则格子 (i,j) 为白色;若为 #,则为黑色。
你最多可以执行一次以下操作:
- 选择一个矩形区域,并将该区域内所有格子涂成黑色。更准确地说,选择满足 1≤h1≤h2≤H 和 1≤w1≤w2≤W 的整数 h1,h2,w1,w2,并将所有满足 h1≤h≤h2 且 w1≤w≤w2 的格子 (h,w) 涂成黑色。
求可得到的不同网格状态的总数。此处,若存在一对整数 (i,j)(其中 1≤i≤H 且 1≤j≤W),使得在一种状态下格子 (i,j) 为白色而在另一种状态下为黑色,则认为这两种网格状态不同。
输入格式
The input is given from Standard Input in the following format:
H W
S1
S2
⋮
SH
输入从标准输入中按以下格式给出:
H W
S1
S2
⋮
SH
输出格式
Output the answer.
输出答案。
输入输出样例
输入#1
2 3 #.. .##
输出#1
7 #.. ##. #.# ### #.. ##. ### .## .## .## .## ### ### ###
输入#2
4 1 # # # #
输出#2
1
输入#3
5 5 ..##. ..#.# .##.# ....# ##.##
输出#3
96
说明/提示
Sample 1 Explanation:
The possible states of the grid obtainable by performing the operation at most once are the following seven:
Constraints
- 1≤H,W
- H×W≤2×105
- H and W are integers.
- Si is a string of length W consisting of
.and#.
样例 1 解释:
最多执行一次操作所能得到的网格可能状态如下所示,共七种:
约束条件
- 1≤H,W
- H×W≤2×105
- H 和 W 均为整数。
- Si 是一个长度为 W 的字符串,仅由字符
.和#组成。
输入解题思路,AI测评打分。不知道怎么写?