#P8865. [NOIP2022] 种花

[NOIP2022] 种花

Description

Xiao C decides to plant a pattern of the letters CCF\texttt{CCF} in his garden, so he wants to know how many planting schemes there are for the letters C\texttt C and F\texttt F respectively. Unfortunately, there are some pits in the garden where flowers cannot be planted, so he hopes you can help solve this problem.

The garden can be viewed as a grid with n×mn \times m positions, with rows numbered 11 to nn from top to bottom, and columns numbered 11 to mm from left to right. Each position may be a pit or not. Use ai,j=1a_{i,j} = 1 to indicate that there is a pit at row ii, column jj, and use ai,j=0a_{i,j} = 0 otherwise.

A planting scheme is called C-\texttt{C-} shaped if there exist x1,x2[1,n]x_1, x_2 \in [1, n] and y0,y1,y2[1,m]y_0, y_1, y_2 \in [1, m], satisfying x1+1<x2x_1 + 1 < x_2 and y0<y1,y2my_0 < y_1, y_2 \leq m, such that the segments from columns y0y_0 to y1y_1 on row x1x_1, from columns y0y_0 to y2y_2 on row x2x_2, and from rows x1x_1 to x2x_2 on column y0y_0 are all not pits, and flowers are planted only on these positions.

A planting scheme is called F-\texttt{F-} shaped if there exist x1,x2,x3[1,n]x_1, x_2, x_3 \in [1, n] and y0,y1,y2[1,m]y_0, y_1, y_2 \in [1, m], satisfying x1+1<x2<x3x_1 + 1 < x_2 < x_3 and y0<y1,y2my_0 < y_1, y_2 \leq m, such that the segments from columns y0y_0 to y1y_1 on row x1x_1, from columns y0y_0 to y2y_2 on row x2x_2, and from rows x1x_1 to x3x_3 on column y0y_0 are all not pits, and flowers are planted only on these positions.

Examples of C-\texttt{C-} shaped and F-\texttt{F-} shaped planting schemes are shown in the explanation of Sample 1.

Now Xiao C wants to know, given nn, mm, and the values {ai,j}\{a_{i,j}\} indicating whether each position is a pit, how many possible C-\texttt{C-} shaped and F-\texttt{F-} shaped planting schemes there are, respectively. Since the answer may be very large, you only need to output the result modulo 998244353998244353. See the output format section for details.

Input Format

The first line contains two integers T,idT, id, denoting the number of test cases and the test point ID, respectively. If the input is a sample, it is guaranteed that id=0id = 0.

Then there are TT test cases. In each test case:

  • The first line contains four integers n,m,c,fn, m, c, f, where nn and mm denote the number of rows and columns of the garden, respectively. The meanings of cc and ff are described in the output format section.
  • The next nn lines each contain a string of length mm consisting only of 00 and 11. The jj-th character of the ii-th string denotes ai,ja_{i,j}, i.e., whether the cell at row ii, column jj in the garden is a pit.

Output Format

Let the numbers of C-\texttt{C-} shaped and F-\texttt{F-} shaped planting schemes in the garden be VCV_C and VFV_F, respectively. For each test case, output one line with two non-negative integers separated by a space, representing (c×VC)mod998244353(c \times V_C) \bmod 998244353 and (f×VF)mod998244353(f \times V_F ) \bmod 998244353, respectively, where amodPa \bmod P denotes aa modulo PP.

1 0
4 3 1 1
001
010
000
000
4 2

Hint

【Explanation of Sample 1】

The four C-\texttt{C-} shaped planting schemes are:

**1 **1 **1 **1
*10 *10 *10 *10
**0 *** *00 *00
000 000 **0 ***

Here *\texttt* denotes planting a flower at that position. Note that the two horizontal strokes of C\texttt C do not need to have the same length.

Similarly, the two F-\texttt{F-} shaped planting schemes are:

**1 **1
*10 *10
**0 ***
*00 *00

【Sample 2】

See the attachments plant/plant2.in\texttt{plant/plant2.in} and plant/plant2.ans\texttt{plant/plant2.ans}.

【Sample 3】

See the attachments plant/plant3.in\texttt{plant/plant3.in} and plant/plant3.ans\texttt{plant/plant3.ans}.

【Constraints】

For all test cases, it is guaranteed that 1T51 \leq T \leq 5, 1n,m1031 \leq n, m \leq 10^3, 0c,f10 \leq c, f \leq 1, and ai,j{0,1}a_{i,j} \in \{0, 1\}.

Test point ID nn mm c=c= f=f= Special property Score
11 1000\leq 1000 00 None 11
22 =3=3 =2=2 11 11 22
33 =4=4 33
44 1000\leq 1000 44
55 1000\leq 1000 A
66 B 66
77 10\leq 10 None 1010
88 20\leq 20 66
99 30\leq 30
1010 50\leq 50 88
1111 100\leq 100 1010
1212 200\leq 200 66
1313 300\leq 300
1414 500\leq 500 88
1515 1000\leq 1000 00 66
1616 11 1414

Special property A: $\forall 1 \leq i \leq n, 1 \leq j \leq \left\lfloor \frac{m}{3} \right\rfloor$, ai,3j=1a_{i, 3 j} = 1.

Special property B: $\forall 1 \leq i \leq \left\lfloor \frac{n}{4} \right\rfloor, 1 \leq j \leq m$, a4i,j=1a_{4 i, j} = 1.

Translated by ChatGPT 5