#P4039. [AHOI2014/JSOI2014] 拼图

[AHOI2014/JSOI2014] 拼图

Description

JYY has recently become obsessed with jigsaw puzzles. As a computer scientist, JYY has a set of black-and-white puzzle pieces. He hopes that by concatenating them properly, the final assembled pattern will contain an all-white subrectangle with the largest possible area.

JYY has SS puzzle pieces, numbered from 11 to SS. The piece numbered ii is a grid rectangle with NN rows and WiW_i columns, where each cell is either black or white. At the beginning, JYY places these SS pieces on the table side by side from left to right in numerical order, forming a large NN by MM rectangle (where M=i=1SWiM=\sum_{i=1}^S W_i).

Later, JYY discovers that by changing the concatenation order of these SS pieces, the area of the maximum all-white subrectangle in the resulting NN by MM rectangle can be increased.

Now JYY wants to know how to arrange the pieces to obtain the largest possible all-white subrectangle. Please help him compute the optimal concatenation order.

Input Format

The first line contains an integer TT, the number of test cases. The descriptions of the test cases follow.

For each test case, the first line contains two integers SS and NN.

Then follow SS groups of input, where the ii-th group corresponds to puzzle piece ii.

In the ii-th group, the first line contains an integer WiW_i; then NN lines describe a NN-row by WiW_i-column 0/10/1 matrix; if the cell at row xx, column yy is 00, then the color at that position of the piece is white, otherwise it is black.

Output Format

For each test case, output one line containing a single integer ans, which denotes the area of the largest possible all-white subrectangle.

1
3 4
4
1001
0000
0010
1001
3
000
010
000
011
2
00
10
01
00
6

Hint

For 100%100\% of the testdata, 1S,N,Wi1051\le S,N,W_i \le 10^5, N×Wi105N \times \sum W_i \le 10^5, 1T31\le T\le 3.

Translated by ChatGPT 5