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 and an integer W (1 ≤ H, W ≤ 1400), representing some dimensions.
A list of H lists, each containing W integers, where each integer 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
Sure! Here is a test case generator for the problem statement "Largest Rectangle":
```python
import random
def tcgen():
H = random.randint(1, 1400)
W = random.randint(1, 1400)
matrix = []
for _ in range(H):
row = [random.randint(0, 1) for _ in range(W)]
matrix.append(row)
return H, W, matrix
def format_input(H, W, matrix):
input_str = f"{H} {W}\n"
for row in matrix:
input_str += " ".join(map(str, row)) + "\n"
return input_str.strip()
# Example usage:
H, W, matrix = tcgen()
print(format_input(H, W, matrix))
```
### Explanation:
1. **Function `tcgen`:**
- It generates random values for `H` and `W` within the range `[1, 1400]`.
- It creates a matrix of size `H x W` where each element is either `0` or `1`.
2. **Function `format_input`:**
- It formats the generated test case to match the input format provided in the problem statement.
### Example Output:
Running the example usage code will produce an output similar to this:
```
3 4
0 1 0 1
1 0 0 0
0 1 1 1
```
This output represents a valid input case for the "Largest Rectangle" problem, with a matrix of size `3 x 4` filled with random `0`s and `1`s.
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)