AT_abc475_f.Rectangle Filling

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There is a grid with HH rows and WW columns. Let the cell at the ii-th row from the top and jj-th column from the left be denoted as cell (i,j)(i, j).

Each cell of the grid is painted white or black: cell (i,j)(i, j) is white if the jj-th character of SiS_i 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,w2h_1, h_2, w_1, w_2 satisfying 1≤h1≤h2≤H1 \leq h_1 \leq h_2 \leq H and 1≤w1≤w2≤W1 \leq w_1 \leq w_2 \leq W, and paint cell (h,w)(h, w) black for every pair of integers (h,w)(h, w) satisfying h1≤h≤h2h_1 \leq h \leq h_2 and w1≤w≤w2w_1 \leq w \leq w_2.

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

有一个 HH 行 WW 列的网格。记从上往下第 ii 行、从左往右第 jj 列的格子为格子 (i,j)(i, j)。

网格中的每个格子被涂成白色或黑色:若字符串 SiS_i 的第 jj 个字符为 .,则格子 (i,j)(i, j) 为白色;若为 #,则为黑色。

你最多可以执行一次以下操作:

  • 选择一个矩形区域,并将该区域内所有格子涂成黑色。更准确地说,选择满足 1≤h1≤h2≤H1 \leq h_1 \leq h_2 \leq H 和 1≤w1≤w2≤W1 \leq w_1 \leq w_2 \leq W 的整数 h1,h2,w1,w2h_1, h_2, w_1, w_2,并将所有满足 h1≤h≤h2h_1 \leq h \leq h_2 且 w1≤w≤w2w_1 \leq w \leq w_2 的格子 (h,w)(h, w) 涂成黑色。

求可得到的不同网格状态的总数。此处,若存在一对整数 (i,j)(i, j)(其中 1≤i≤H1 \leq i \leq H 且 1≤j≤W1 \leq j \leq W),使得在一种状态下格子 (i,j)(i, j) 为白色而在另一种状态下为黑色,则认为这两种网格状态不同。

输入格式

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

HH WW
S1S_1
S2S_2
⋮\vdots
SHS_H

输入从标准输入中按以下格式给出:

HH WW
S1S_1
S2S_2
⋮\vdots
SHS_H

输出格式

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,W1 \leq H, W
  • H×W≤2×105H \times W \leq 2 \times 10^5
  • HH and WW are integers.
  • SiS_i is a string of length WW consisting of . and #.

样例 1 解释:
最多执行一次操作所能得到的网格可能状态如下所示,共七种:

约束条件

  • 1≤H,W1 \leq H, W
  • H×W≤2×105H \times W \leq 2 \times 10^5
  • HH 和 WW 均为整数。
  • SiS_i 是一个长度为 WW 的字符串,仅由字符 . 和 # 组成。

输入解题思路,AI测评打分。不知道怎么写?

首页