5484.Easily Distinguishable Triangles

Time Limit: 1s Memory Limit: 256MB

Eva loves painting. Today she is working with a square canvas of $n \times n$ unit cells. Each cell is painted white, painted black, or empty--- not painted at all.

Eva is going to draw a black triangle inside each empty cell. She wants each triangle to be right-angled and have an area of $\frac{1}{2}$ square unit cells. Thus, there are four ways to draw a single triangle:

UdaBxEb5wTx37XCnNQ3wdOEK2bvjBl1TzuquUzHT.png

Each triangle is a piece of art, and Eva wants them to be easily distinguishable from the rest of the painting. To achieve that, no two black triangles may share a common side with each other, and no black triangle may share a common side with a black square. Note that two black squares are allowed to share a common side.

Help Eva to find out how many ways there are to finish her painting. Since the number can be large, calculate it modulo $998\,244\,353$.

Input Format(From the terminal/stdin)

The first line contains a single integer $n$~--- the side length of the canvas ($1 \le n \le 1000$).

The next $n$ lines describe the canvas from top to bottom. The $i$-th of these lines contains $n$ characters $s_{i, 1}, s_{i, 2}, \ldots, s_{i, n}$. If $s_{i, j} =$ ., the cell in the $i$-th row and the $j$-th column of the canvas is painted white. If $s_{i, j} =$ #, that cell is painted black. If $s_{i, j} =$ ?, that cell is empty.

Output Format(To the terminal/stdout)

Print a single integer denoting the number of ways to finish Eva's painting, modulo $998\,244\,353$.

Sample Input 1

Copy
2
.?
?#
 \n
  \n
  \n

Sample Output 1

Copy
4
 \n

Sample Input 2

Copy
3
#??
#??
?##
 \n
   \n
   \n
   \n

Sample Output 2

Copy
1
 \n

Sample Input 3

Copy
3
.#.
#?#
.#.
 \n
   \n
   \n
   \n

Sample Output 3

Copy
0
 \n

Hints

In the first example test, there are $4$ ways to finish the painting, as illustrated below:

TaigMF4SJFr7qLfZYHTiJ9ORWuevBox12wLeDnjL.png
In the second example test, there is a single way to finish the painting:

OYtbAeGGV9ttqPmh4rw0PZoamkesr5A6SdoPSWo7.png

In the third example test, regardless of how Eva draws the triangle in the center cell, it will share two sides with black squares.

Source: NWRRC 2022

Submit

请先 登录

© 2025 FAQs