NOIP '22 P1 - Flower Planting

View as PDF

Submit solution

Points: 10 (partial)
Time limit: 1.0s
Memory limit: 512M

Problem type

Little C decided to plant the pattern of CCF in his garden, so he wanted to know how many flowering schemes there are for the two letters C and F; He wants you to help him with this problem.

A garden can be viewed as a grid map with n×m locations, which are the 1st to nth rows from top to bottom, and the 1st to mth columns from left to right, where each location may be mud or not. Specifically, ai,j=1 indicates that there is mud at the position of row i and column j, and ai,j=0 indicates that there is no mud at this position.

A planting scheme is called C-shaped, if there exist x1,x2[1,n], and y0,y1,y2[1,m], such that x1+1<x2, and y0<y1,y2m, so that the y0th to y1th column of the x1th row, the y0th to y2th column of the x2th row, and the x1th to x2th row of the y0th column are not mud, and flowers are only planted in these positions.

A planting scheme is called F-shaped, if there exist x1,x2,x3[1,n], and y0,y1,y2[1,m], satisfying x1+1<x2<x3, and y0<y1,y2m, so that the y0 to y1 column of the x1 row, the y0 to y2 column of the x2 row, and the x1 to x3 row of the y0 column are not mud, and flowers are only planted in these positions.

Sample 1 gives examples of C-shape and F-shape planting schemes.

Now little C wants to know, given n, m and the value {ai,j} indicating whether each position is mud, how many possibilities are there for C-shaped and F-shaped flowering schemes? Since the answer may be very large, you only need to output the result modulo 998244353. Please refer to the output format section for specific output results.

Input Specification

The first line contains two integers T, id, which respectively represent the number of data sets and the number of test points. All sample data have id=0.

Next, there are T sets of data, in each set of data:

The first line contains four integers n, m, c, f, where n, m represent the number of rows and columns of the garden respectively, and see the output format section for the meaning of c, f.

The next n lines, each line contains a string of length m and only contains 0 and 1, where the jth character of the ith string represents ai,j, that is, is the jth column of the ith row in the garden mud.

Output Specification

For each set of data, if there are VC and VF C-shaped and F-shaped flower planting schemes in the garden respectively, you need to output two non-negative integers separated by a space, (c×VC)mod998244353, and (f×VF)mod998244353, where amodP represents the result of taking the remainder of a divided by P.

Sample Input 1

Copy
1 0
4 3 1 1
001
010
000
000

Sample Output 1

Copy
4 2

Explanation of Sample 1

The four C-typed plans are:

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

Where * means to plant flowers at this position. Note that the two bars of C can be of different lengths.

Similarly, the two F-shape planting schemes are:

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

Additional Samples

Additional sample cases can be found here.

Constraints

For all data, it is guaranteed that 1T5, 1n,m103, 0c,f1, ai,j{0,1}.

CasenmcfSpecial PropertyPoints
11000100000none1
2=3=2112
3=43
410004
510001in,1jm3,ai,3j=14
61in4,1jm,a4i,j=16
71010none10
820206
930306
1050508
1110010010
122002006
133003006
145005008
151000100006
16114

Comments

There are no comments at the moment.