CF1359B.New Theatre Square

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You might have remembered Theatre square from the problem 1A. Now it's finally getting repaved.

The square still has a rectangular shape of n×mn \times m meters. However, the picture is about to get more complicated now. Let ai,ja_{i,j} be the jj-th square in the ii-th row of the pavement.

You are given the picture of the squares:

  • if $a_{i,j} = $ "*", then the jj-th square in the ii-th row should be black;
  • if $a_{i,j} = $ ".", then the jj-th square in the ii-th row should be white.

The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:

  • 1×11 \times 1 tiles — each tile costs xx burles and covers exactly 11 square;
  • 1×21 \times 2 tiles — each tile costs yy burles and covers exactly 22 adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into 1×11 \times 1 tiles.

You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.

What is the smallest total price of the tiles needed to cover all the white squares?

你可能还记得 题目 1A 中的剧院广场。现在它终于要重新铺设了。

广场仍为 n×mn \times m 米的矩形。但如今情况将变得更为复杂。设 ai,ja_{i,j} 表示铺装图案中第 ii 行第 jj 列的方格。

你将获得如下铺装图案:

  • 若 $a_{i,j} = $ "*",则第 ii 行第 jj 列的方格应为黑色;
  • 若 $a_{i,j} = $ ".",则第 ii 行第 jj 列的方格应为白色。

黑色方格已铺设完毕。你需要铺设所有白色方格。可供选择的地砖有两种:

  • 1×11 \times 1 地砖 —— 每块价格为 xx 卢布,恰好覆盖 11 个方格;
  • 1×21 \times 2 地砖 —— 每块价格为 yy 卢布,恰好覆盖同一行中相邻的 22 个方格。注意:不允许旋转这些地砖,也不允许将其切割为 1×11 \times 1 地砖。

你需要覆盖所有白色方格,且任意两块地砖不得重叠,黑色方格也不得被地砖覆盖。

覆盖所有白色方格所需的地砖最小总价格是多少?

输入格式

The first line contains a single integer tt (1≤t≤5001 \le t \le 500) — the number of testcases. Then the description of tt testcases follow.

The first line of each testcase contains four integers nn, mm, xx and yy (1≤n≤1001 \le n \le 100; 1≤m≤10001 \le m \le 1000; 1≤x,y≤10001 \le x, y \le 1000) — the size of the Theatre square, the price of the 1×11 \times 1 tile and the price of the 1×21 \times 2 tile.

Each of the next nn lines contains mm characters. The jj-th character in the ii-th line is ai,ja_{i,j}. If $a_{i,j} = $ "*", then the jj-th square in the ii-th row should be black, and if $a_{i,j} = $ ".", then the jj-th square in the ii-th row should be white.

It's guaranteed that the sum of n×mn \times m over all testcases doesn't exceed 10510^5.

第一行包含一个整数 tt(1≤t≤5001 \le t \le 500),表示测试用例的数量。随后是 tt 个测试用例的描述。

每个测试用例的第一行包含四个整数 nn、mm、xx 和 yy(1≤n≤1001 \le n \le 100;1≤m≤10001 \le m \le 1000;1≤x,y≤10001 \le x, y \le 1000),分别表示剧院广场的尺寸、1×11 \times 1 地砖的价格以及 1×21 \times 2 地砖的价格。

接下来的 nn 行,每行包含 mm 个字符。第 ii 行的第 jj 个字符为 ai,ja_{i,j}。若 $a_{i,j} = $ "*",则表示第 ii 行第 jj 列的方格应为黑色;若 $a_{i,j} = $ ".",则表示第 ii 行第 jj 列的方格应为白色。

保证所有测试用例中 n×mn \times m 的总和不超过 10510^5。

输出格式

For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.

对于每个测试用例,输出一个整数——覆盖所有白色方格所需的瓷砖的最小总价格(单位:burles)。

输入输出样例

  • 输入#1

    4
    1 1 10 1
    .
    1 2 10 1
    ..
    2 1 10 1
    .
    .
    3 3 3 7
    ..*
    *..
    .*.

    输出#1

    10
    1
    20
    18

说明/提示

In the first testcase you are required to use a single 1×11 \times 1 tile, even though 1×21 \times 2 tile is cheaper. So the total price is 1010 burles.

In the second testcase you can either use two 1×11 \times 1 tiles and spend 2020 burles or use a single 1×21 \times 2 tile and spend 11 burle. The second option is cheaper, thus the answer is 11.

The third testcase shows that you can't rotate 1×21 \times 2 tiles. You still have to use two 1×11 \times 1 tiles for the total price of 2020.

In the fourth testcase the cheapest way is to use 1×11 \times 1 tiles everywhere. The total cost is 6⋅3=186 \cdot 3 = 18.

在第一个测试用例中,您必须使用一块 1×11 \times 1 瓷砖,尽管 1×21 \times 2 瓷砖更便宜。因此总价格为 1010 卢布。

在第二个测试用例中,您可以选择使用两块 1×11 \times 1 瓷砖,花费 2020 卢布;或者使用一块 1×21 \times 2 瓷砖,花费 11 卢布。后一种方案更便宜,因此答案为 11。

第三个测试用例表明,您不能旋转 1×21 \times 2 瓷砖。您仍需使用两块 1×11 \times 1 瓷砖,总价格为 2020。

在第四个测试用例中,最便宜的方式是在所有位置均使用 1×11 \times 1 瓷砖。总费用为 6⋅3=186 \cdot 3 = 18。

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

首页