Problem p01559 - Generation 3

Orig Description

MinimumCostPath
There is an NxN square grid.
(Figure for the case of N=3)
The cost to move to an adjacent square is 1. However, diagonal movement is not allowed.
Also, there are M squares with obstacles, and it is not allowed to enter those squares.
How many ways are there to move from square (1,1) to square (N,N) with the minimum cost?
Since the answer can be large, output it by taking the MOD of 1000000009 (=109+9).
Input
The input is given in the following format:
N MX1 Y1X2 Y2……XM YM
Xi, Yi indicate that there is an obstacle at (Xi, Yi).
Constraints
2 ≤ N ≤ 106
 0 ≤ M ≤ 50
 1 ≤ Xi , Yi ≤ N
 i ≠ j implies (Xi, Yi) ≠ (Xj, Yj)
 (Xi, Yi) ≠ (1, 1)
 (Xi, Yi) ≠ (N, N)
Output
Output the total number of routes in one line. If there is no route to move from square (1,1) to square (N,N), output 0.
Sample Input 1
3 0
Output for the Sample Input 1
6
Corresponds to the following figure.
Sample Input 2
3 1
2 2
Output for the Sample Input 2
2
Corresponds to the following figure.
Sample Input 3
5 8
4 3
2 1
4 2
4 4
3 4
2 2
2 4
1 4
Output for the Sample Input 3
1
Corresponds to the following figure.
Sample Input 4
1000 10
104 87
637 366
393 681
215 604
707 876
943 414
95 327
93 415
663 596
661 842
Output for the Sample Input 4
340340391
Sample Input 5
2 2
1 2
2 1
Output for the Sample Input 5
0

Extracted Specification

An integer N (2 ≤ N ≤ 10^6), representing some quantity or size.
An integer M (0 ≤ M ≤ 50), representing some quantity or size.
M pairs of integers (Xi, Yi), each pair representing coordinates with values (1 ≤ Xi, Yi ≤ N).

### Example Input:

```
3 1
2 2
```

### Function Signature:
Write a function f(N, M, obstacles) that takes in the input.
def f(N: int, M: int, obstacles: List[Tuple[int, int]]): 
    ''' 
    N: an integer 
    M: an integer 
    obstacles: a list of tuples, each containing two integers
    '''

Test Case Generator

Certainly! Here is the test case generator for the "MinimumCostPath" problem:

```python
import random

def tcgen():
    # Generate a random N within the constraints
    N = random.randint(2, 10**6)
    
    # Generate a random M within the constraints
    M = random.randint(0, 50)
    
    obstacles = set()
    while len(obstacles) < M:
        x = random.randint(1, N)
        y = random.randint(1, N)
        if (x, y) != (1, 1) and (x, y) != (N, N) and (x, y) not in obstacles:
            obstacles.add((x, y))
    
    obstacles = list(obstacles)
    
    # Convert obstacles to the required format
    obstacle_str = ""
    for x, y in obstacles:
        obstacle_str += f"{x} {y}\n"
    
    return f"{N} {M}\n{obstacle_str}"

# Example usage
print(tcgen())
```

The test case generator `tcgen` follows these steps:

1. It generates a random `N` between 2 and \(10^6\).
2. It generates a random `M` between 0 and 50.
3. It creates a set of unique obstacle coordinates while ensuring that the coordinates do not include the starting point `(1, 1)` or the ending point `(N, N)`.
4. It formats the obstacle coordinates into the required string format.

You can use this generator to create test cases for your problem statement. Here is an example output of running the generator:

```
100 10
45 67
23 89
12 34
56 78
90 12
34 56
78 90
12 23
45 56
67 78
```

Feel free to integrate or modify this generator as needed for your testing purposes!

Extract Arguments

def extract_arguments(fh):
    N, M = map(int, fh.readline().strip().split())
    obstacles = []
    for _ in range(M):
        Xi, Yi = map(int, fh.readline().strip().split())
        obstacles.append((Xi, Yi))
    return N, M, obstacles