Problem p03133 - Generation 2

Orig Description

Score : 800 points
Problem StatementThere is a square grid with N rows and M columns.
Each square contains an integer: 0 or 1. The square at the i-th row from the top and the j-th column from the left contains a_{ij}.
Among the 2^{N+M} possible pairs of a subset A of the rows and a subset B of the columns, find the number of the pairs that satisfy the following condition, modulo 998244353:
The sum of the |A||B| numbers contained in the intersection of the rows belonging to A and the columns belonging to B, is odd.
Constraints
1 \leq N,M \leq 300
0 \leq a_{i,j} \leq 1(1\leq i\leq N,1\leq j\leq M)
All values in input are integers.
InputInput is given from Standard Input in the following format:
N M
a_{11} ... a_{1M}
:
a_{N1} ... a_{NM}
OutputPrint the number of the pairs of a subset of the rows and a subset of the columns that satisfy the condition, modulo 998244353.
Sample Input 12 2
0 1
1 0
Sample Output 16
For example, if A consists of the first row and B consists of both columns, the sum of the numbers contained in the intersection is 0+1=1.
Sample Input 22 3
0 0 0
0 1 0
Sample Output 28

Extracted Specification

An integer N (1 ≤ N ≤ 300), representing some quantity or size.
An integer M (1 ≤ M ≤ 300), representing another quantity or size.
A 2D list of integers A of size N x M, where each integer is between 0 and 1.

### Example Input:

```
2 2
0 1
1 0
```

### Function Signature:
Write a function f(N, M, A) that takes in the input. 
def f(N: int, M: int, A: List[List[int]]): 
    ''' 
    N: an integer 
    M: an integer
    A: a 2D list of integers
    '''

Test Case Generator

Certainly! Below is the test case generator for the given problem statement.

```python
import random

def generate_test_case():
    # Constraints
    N = random.randint(1, 300)
    M = random.randint(1, 300)
    
    # Generate the grid values (only 0s and 1s)
    grid = [[random.randint(0, 1) for _ in range(M)] for _ in range(N)]
    
    return N, M, grid

def format_test_case(N, M, grid):
    test_case = f"{N} {M}\n"
    for row in grid:
        test_case += " ".join(map(str, row)) + "\n"
    return test_case

# Example usage
N, M, grid = generate_test_case()
print(format_test_case(N, M, grid))
```

This script defines two functions: `generate_test_case` to create a random test case following the constraints, and `format_test_case` to format the generated test case as a string in the required input format.

Here's how the functions work:
- `generate_test_case` generates random values for \( N \) and \( M \) within their respective constraints. Then, it creates an \( N \times M \) grid with each cell containing either 0 or 1.
- `format_test_case` takes the generated grid and formats it as a string in the required input format for the problem.

You can run these functions to create and print a test case for the problem.

Extract Arguments

def extract_arguments(fh):
    N, M = map(int, fh.readline().strip().split())
    grid = [list(map(int, fh.readline().strip().split())) for _ in range(N)]
    return N, M, grid