Nice pattern
Limits: 2 sec., 512 MiB
This statement was translated automatically from Ukrainian.
Zenyk has a huge grid paper sheet. This sheet has a size of \(n \cdot 2^y \times m \cdot 2^x\). To please Marichka, Zenyk decided to cut out a nice pattern from it. To do this, he folded the paper in half vertically \(y\) times, and then horizontally \(x\) times. Each time Zenyk folded the paper towards the top-left corner — that is, the fold was always on the right (during horizontal folding), or at the bottom (during vertical folding). After such manipulations, he obtained a sheet of size \(n \times m\).
Then Zenyk took scissors, cut out some cells of the paper and threw them away, and solemnly called everything that remained a pattern and gave it to Marichka. Now Marichka is very curious about how many pieces of paper she has. Since this number can be very large, output the remainder of the division of this quantity by \(998244353\).
Note that pieces of paper that touch only by a corner are not connected to each other.
Input
The first line contains four integers \(n\), \(m\), \(y\), and \(x\) — the size of the sheet after all folds and the number of vertical and horizontal folds, respectively.
The next \(n\) lines contain strings
of length \(m\) consisting of the
characters . and #. The character
# means that Zenyk kept this cell, and the character
. means that he cut it out.
Output
In a single line, output the number of pieces of paper modulo \(998244353\).
Constraints
\(1 \le n, m \le 500\),
\(0 \le y, x \le 10^9\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 2 2 1 2 ## #. | 1 |
| Input (stdin) | Output (stdout) |
|---|---|
| 3 4 2 1 ##.. #.#. #..# | 12 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 7 74 47 #..#.#. #.#..## ..#..#. #..#.#. | 621022578 |
Notes
Unfolding of Zenyk’s "pattern" from the second example. Gray indicates the cells that remained after cutting.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|