第 475 场 AtCoder Beginner Contest
F
矩形填充
Rectangle Filling
AtCoder
⌀ 1916
原题
← EG →

矩形填充AI (CI翻译)

Problem Statement

题目描述

AI (CI翻译)

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)$.

有一个 $H$ 行 $W$ 列的网格。从上往下第 $i$ 行、从左往右第 $j$ 列的格子记为格子 $(i, j)$。AI (CI翻译)

Each cell of the grid is painted white or black: cell $(i, j)$ is white if the $j$-th character of $S_i$ is ., and black if it is #.

网格中的每个格子都被涂成白色或黑色:如果 $S_i$ 的第 $j$ 个字符是 .,则格子 $(i, j)$ 为白色;如果是 #,则为黑色。AI (CI翻译)

You can perform the following operation at most once.

你可以至多执行一次以下操作。AI (CI翻译)

  • Choose a rectangular region, and paint all cells within that region black. More formally, choose integers $h_1, h_2, w_1, w_2$ satisfying $1 \leq h_1 \leq h_2 \leq H$ and $1 \leq w_1 \leq w_2 \leq W$, and paint cell $(h, w)$ black for every pair of integers $(h, w)$ satisfying $h_1 \leq h \leq h_2$ and $w_1 \leq w \leq w_2$.
  • 选择一个矩形区域,并将其中的所有格子涂成黑色。更正式地说,选择满足 $1 \leq h_1 \leq h_2 \leq H$ 和 $1 \leq w_1 \leq w_2 \leq W$ 的整数 $h_1, h_2, w_1, w_2$,并将所有满足 $h_1 \leq h \leq h_2$ 且 $w_1 \leq w \leq w_2$ 的整数对 $(h, w)$ 所对应的格子涂成黑色。
AI (CI翻译)

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 \leq i \leq H$ and $1 \leq j \leq W$ such that cell $(i, j)$ is painted white in one state and painted black in the other state.

求可以得到的网格状态数。如果存在一对整数 $(i, j)$,满足 $1 \leq i \leq H$ 且 $1 \leq j \leq W$,并且格子 $(i, j)$ 在一个状态中为白色、在另一个状态中为黑色,则认为这两个网格状态不同。AI (CI翻译)

Constraints

约束条件

AI (CI翻译)
  • $1 \leq H, W$
  • $H \times W \leq 2 \times 10^5$
  • $H$ and $W$ are integers.
  • $S_i$ is a string of length $W$ consisting of . and #.
  • $1 \leq H, W$
  • $H \times W \leq 2 \times 10^5$
  • $H$ 和 $W$ 均为整数。
  • $S_i$ 是一个长度为 $W$、由 . 和 # 组成的字符串。
AI (CI翻译)

Input

输入格式

AI (CI翻译)

The input is given from Standard Input in the following format:

输入从标准输入按以下格式给出:AI (CI翻译)

H W
S_1
S_2
\vdots
S_H

H W
S_1
S_2
\vdots
S_H
AI (CI翻译)

Output

输出格式

AI (CI翻译)

Output the answer.

输出答案。AI (CI翻译)

样例

Input #1
2 3
#..
.##
Output #1
7
The possible states of the grid obtainable by performing the operation at most once are the following seven:
Input #2
4 1
#
#
#
#
Output #2
1
Input #3
5 5
..##.
..#.#
.##.#
....#
##.##
Output #3
96
题目信息
题号
abc475_f
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(gpt-6.1-sol),如有出入请以原文为准。