QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#6150. Jigsaw Puzzle

Statistics

JYY has recently become obsessed with jigsaw puzzles. As a computer scientist, JYY has a set of black and white puzzle pieces, and he hopes to arrange them in a reasonable way so that the final pattern contains the largest possible all-white sub-rectangle.

JYY has a total of $S$ puzzle pieces, numbered from 1 to $S$. The puzzle piece numbered $i$ is a grid rectangle of $N$ rows and $W_i$ columns, where each cell is either black or white.

Initially, JYY places his $S$ puzzle pieces on the table in order of their numbers, connected side-by-side to form a large rectangle of $N$ rows and $M$ columns (where $M = \sum_{i=1}^{S} W_i$).

Later, JYY discovers that he can change the connection order of these $S$ puzzle pieces to increase the area of the largest all-white sub-rectangle in the resulting $N \times M$ large rectangle.

Now, JYY wants to know how to arrange them to obtain the largest all-white sub-rectangle. Please help him calculate the best arrangement.

Input

The input contains multiple test cases. The first line of the input file contains an integer $T$, representing the number of test cases. The test cases follow in order.

The first line of each test case contains two integers $S$ and $N$.

Then follow $S$ blocks of input, where the $i$-th block corresponds to the puzzle piece numbered $i$.

In the $i$-th block: The first line contains an integer $W_i$. The next $N$ lines describe an $N \times W_i$ grid of 0s and 1s. A 0 at row $x$ and column $y$ indicates that the cell in the puzzle piece is white, while a 1 indicates that it is black.

Output

For each test case, output a single line containing an integer $ans$, representing the maximum possible area of an all-white sub-rectangle.

Examples

Input 1

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

Output 1

6

Note

The large rectangle formed by the optimal arrangement is:

000100100
010000010
000001001
011100100

The bolded part is the white sub-rectangle with an area of 6.

Constraints

  • For 10% of the data: $S = 1, N \le 30, W_i \le 30$;
  • For 30% of the data: $S \le 3$;
  • For 50% of the data: $S \le 1000$;
  • For 100% of the data: $1 \le S, N, W_i \le 10^5$, $N \times \sum_{i=1}^{S} W_i \le 10^5$, $T \le 3$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.