codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1359B.md (2976B)


      1 Source: https://codeforces.com/problemset/problem/1359/B
      2 
      3 B. New Theatre Square
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved.
     22 
     23 The square still has a rectangular shape of $n \times m$ meters. However, the picture is about to get more complicated now. Let $a_{i,j}$ be the $j$-th square in the $i$-th row of the pavement.
     24 
     25 You are given the picture of the squares:
     26 
     27 * if $a_{i,j} = $ "*", then the $j$-th square in the $i$-th row should be black;
     28 * if $a_{i,j} = $ ".", then the $j$-th square in the $i$-th row should be white.
     29 
     30 The black squares are paved already. You have to pave the white squares. There are two options for pavement tiles:
     31 
     32 * $1 \times 1$ tiles — each tile costs $x$ burles and covers exactly $1$ square;
     33 * $1 \times 2$ tiles — each tile costs $y$ burles and covers exactly $2$ adjacent squares of the same row. Note that you are not allowed to rotate these tiles or cut them into $1 \times 1$ tiles.
     34 
     35 You should cover all the white squares, no two tiles should overlap and no black squares should be covered by tiles.
     36 
     37 What is the smallest total price of the tiles needed to cover all the white squares?
     38 
     39 Input
     40 
     41 The first line contains a single integer $t$ ($1 \le t \le 500$) — the number of testcases. Then the description of $t$ testcases follow.
     42 
     43 The first line of each testcase contains four integers $n$, $m$, $x$ and $y$ ($1 \le n \le 100$; $1 \le m \le 1000$; $1 \le x, y \le 1000$) — the size of the Theatre square, the price of the $1 \times 1$ tile and the price of the $1 \times 2$ tile.
     44 
     45 Each of the next $n$ lines contains $m$ characters. The $j$-th character in the $i$-th line is $a_{i,j}$. If $a_{i,j} = $ "*", then the $j$-th square in the $i$-th row should be black, and if $a_{i,j} = $ ".", then the $j$-th square in the $i$-th row should be white.
     46 
     47 It's guaranteed that the sum of $n \times m$ over all testcases doesn't exceed $10^5$.
     48 
     49 Output
     50 
     51 For each testcase print a single integer — the smallest total price of the tiles needed to cover all the white squares in burles.
     52 
     53 Example
     54 
     55 Input
     56 
     57 ```
     58 4
     59 1 1 10 1
     60 .
     61 1 2 10 1
     62 ..
     63 2 1 10 1
     64 .
     65 .
     66 3 3 3 7
     67 ..*
     68 *..
     69 .*.
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 10
     76 1
     77 20
     78 18
     79 ```
     80 
     81 Note
     82 
     83 In the first testcase you are required to use a single $1 \times 1$ tile, even though $1 \times 2$ tile is cheaper. So the total price is $10$ burles.
     84 
     85 In the second testcase you can either use two $1 \times 1$ tiles and spend $20$ burles or use a single $1 \times 2$ tile and spend $1$ burle. The second option is cheaper, thus the answer is $1$.
     86 
     87 The third testcase shows that you can't rotate $1 \times 2$ tiles. You still have to use two $1 \times 1$ tiles for the total price of $20$.
     88 
     89 In the fourth testcase the cheapest way is to use $1 \times 1$ tiles everywhere. The total cost is $6 \cdot 3 = 18$.