Problem p02123 - Generation 1

Orig Description

Problem M: Fissure Puzzle Hard
Problem
There is a grid consisting of $N \times N$ squares. All squares are initially white. We increase the number of black squares following the procedure below.
Choose a white square in a cell that is on an even-numbered row and an even-numbered column. The chosen square is changed to black. Furthermore, the white squares adjacent to the chosen square in each direction, north, south, east, and west, are changed to black in a chain until there is no white square in that direction. (See the example below.)
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
□□□□□□□□□
↓ choose the square in the 4th row from the top and the 6th column
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
■■■■■■■■■
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
↓ choose the square in the 2nd row from the top and the 2nd column
□■□□□■□□□
■■■■■■□□□
□■□□□■□□□
■■■■■■■■■
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
□□□□□■□□□
↓ choose the square in the 6th row from the top and the 8th column
□■□□□■□□□
■■■■■■□□□
□■□□□■□□□
■■■■■■■■■
□□□□□■□■□
□□□□□■■■■
□□□□□■□■□
□□□□□■□■□
□□□□□■□■□
You want to create a grid where the color of the square at the $i$-th row from the top and the $j$-th column from the left is $A_{i,j}$. Determine whether it is possible to create such a grid. If possible, find the places and order of the squares to be selected.
Input
The input is given in the following format.
$N$
$A_{1,1}$ $A_{1,2}$ ... $A_{1,N}$
$A_{2,1}$ $A_{2,2}$ ... $A_{2,N}$
...
$A_{N,1}$ $A_{N,2}$ ... $A_{N,N}$
  When $A_{i,j}$ is 'o', it means that the square at the $i$-th row from the top and the $j$-th column from the left is white, and when it is 'x', it means that the square is black.
Constraints
$3 \le N \le 2047$
$N$ is odd.
$A_{i,j}$ is either 'o' or 'x'.
Output
If it is impossible, output -1 in one line.
If it is possible, output the number of squares to be selected in the first line, the row number from the top of the $i$-th square to be selected in the $2i$-th line, and the column number from the left to be selected in the $2i+1$-th line. If it is not uniquely determined, output the smallest one in lexicographic order.
Sample Input 1
5
oxooo
oxooo
oxooo
xxxxx
oxooo
Sample Output 1
1
4
2
Sample Input 2
9
oxoooooxo
oxxxxxxxx
oxoooooxo
xxxxxxxxx
oxoxooooo
oxxxxxxxx
oxoxoxooo
oxoxxxxxx
oxoxoxooo
Sample Output 2
4
4
2
2
8
6
4
8
6
Sample Input 3
3
oxx
oxx
ooo
Sample Output 3
-1

Extracted Specification

An integer N (3 ≤ N ≤ 2047), where N is odd.
An N x N grid of characters where each character is either 'o' or 'x'.

### Example Input:

```
5
oxooo
oxooo
oxooo
xxxxx
oxooo
```

### Function Signature:
Write a function f(N, A) that takes in the input. 
```python
def f(N: int, A: List[List[str]]): 
    ''' 
    N: an integer 
    A: a list of lists of characters
    '''
```

Test Case Generator

To generate test cases for the problem "Fissure Puzzle Hard," we need to consider the constraints and structure of the input. Here's a Python function to generate random test cases:

```python
import random

def tcgen():
    # Generate a random odd N in the range [3, 2047]
    N = random.choice([i for i in range(3, 2048) if i % 2 != 0])
    
    # Generate the N x N grid with 'o' and 'x'
    A = []
    for _ in range(N):
        row = ''.join(random.choice(['o', 'x']) for _ in range(N))
        A.append(row)
    
    return N, A

# Function to print the generated test case
def print_test_case(N, A):
    print(N)
    for row in A:
        print(row)

# Example usage
N, A = tcgen()
print_test_case(N, A)
```

### Explanation:

1. **N Generation**: We randomly select an odd integer \( N \) within the range [3, 2047]. We ensure the chosen \( N \) is odd by filtering with `if i % 2 != 0`.

2. **Grid Generation**: We generate an \( N \times N \) grid where each cell is randomly either 'o' (white) or 'x' (black). This is done by iterating \( N \) times and for each row, creating a string of length \( N \) with random choices between 'o' and 'x'.

3. **Output Function**: `print_test_case` is a helper function to print the generated test case in the required format.

You can run this script to generate and print random test cases for the problem. Each execution will produce a different valid test case that adheres to the constraints specified in the problem statement.

Extract Arguments

def extract_arguments(fh):
    N = int(fh.readline().strip())
    A = [fh.readline().strip() for _ in range(N)]
    return N, A