Orig Description
Largest Rectangle
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest rectangle which only contains 0s.
Input
H W
c1,1 c1,2 ... c1,W
c2,1 c2,2 ... c2,W
:
cH,1 cH,2 ... cH,W
In the first line, two integers H and W separated by a space character are given. In the following H lines, ci,j, elements of the H × W matrix, are given.
Output
Print the area (the number of 0s) of the largest rectangle.
Constraints
1 ≤ H, W ≤ 1,400
Sample Input
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
Sample Output
6
Extracted Specification
An integer H (1 ≤ H ≤ 1,400), representing some quantity or size.
An integer W (1 ≤ W ≤ 1,400), representing some quantity or size.
A matrix of size H × W, where each element is either 0 or 1.
### Example Input:
```
4 5
0 0 1 0 0
1 0 0 0 0
0 0 0 1 0
0 0 0 1 0
```
### Function Signature:
Write a function f(H, W, matrix) that takes in the input.
```python
def f(H: int, W: int, matrix: List[List[int]]):
'''
H: an integer
W: an integer
matrix: a list of lists of integers
'''
```
Test Case Generator
Here is a test case generator for the "Largest Rectangle" problem:
```python
import random
def tcgen():
H = random.randint(1, 1400)
W = random.randint(1, 1400)
matrix = [[random.randint(0, 1) for _ in range(W)] for _ in range(H)]
return H, W, matrix
# Function to print the generated test case in the required format
def print_test_case(H, W, matrix):
print(f"{H} {W}")
for row in matrix:
print(' '.join(map(str, row)))
# Example usage
H, W, matrix = tcgen()
print_test_case(H, W, matrix)
```
This generator creates a random height `H` and width `W` for the matrix, both within the specified constraint of 1 to 1400. It then generates a `HxW` matrix of random 0s and 1s. Finally, the `print_test_case` function formats the generated test case to match the input format required by the problem statement.
You can run the generator multiple times to produce different test cases for testing the solution to the problem.
Extract Arguments
def extract_arguments(fh):
H, W = map(int, fh.readline().strip().split())
matrix = []
for _ in range(H):
row = list(map(int, fh.readline().strip().split()))
matrix.append(row)
return H, W, matrix
# if __name__ == "__main__":
# input_path = sys.argv[1]
# with open(input_path, 'r') as fh:
# H, W, matrix = extract_arguments(fh)
# f(H, W, matrix)