#P10714. Two-Move Star Capture
Two-Move Star Capture
Two-Move Star Capture
In this problem, you are given an \( n \times m \) chessboard containing \( k \) stars at distinct positions. A catcher is initially positioned at cell \( (x, y) \). The catcher can move horizontally or vertically (i.e. on the same row or same column) to any other cell within the board (i.e. new position \( (x', y') \) must satisfy \( 1 \le x' \le n \) and \( 1 \le y' \le m \), and \( (x', y') \neq (x, y) \)). When the catcher moves from one cell to another, it captures all stars that lie on the straight line segment connecting the starting and ending cell (including both endpoints). A captured star disappears immediately.
The game consists of exactly two moves. In each move the catcher simply and arbitrarily chooses a valid destination (there are exactly \( n+m-2 \) choices for the first move, and similarly \( n+m-2 \) choices for the second move from its current location). Thus, there are \( (n+m-2)^2 \) distinct two‐move strategies.
Your task is: For all two‐move strategies, determine the sum of the numbers of stars captured (a star captured in the first move will not be captured again in the second move). Since the answer can be large, output it modulo \( 10^9+7 \).
Note: The path of a move is defined as the set of cells on the straight line between the start and end positions in that move. For a horizontal move (the row remains unchanged) from \( (x, y) \) to \( (x, y') \), a star at \( (x, b) \) is captured if \( \min(y, y') \le b \le \max(y, y') \). Similarly, for a vertical move from \( (x, y) \) to \( (x', y) \), a star at \( (a, y) \) is captured if \( \min(x, x') \le a \le \max(x, x') \).
inputFormat
The input consists of several lines.
- The first line contains three integers \( n \), \( m \), and \( k \) indicating the dimensions of the board and the number of stars.
- The second line contains two integers \( x \) and \( y \), the initial coordinates of the catcher.
- Each of the next \( k \) lines contains two integers \( a_i \) and \( b_i \) representing the position of a star.
It is guaranteed that the stars are located at distinct positions.
outputFormat
Output a single integer, the sum over all \( (n+m-2)^2 \) two‐move strategies of the number of stars captured, modulo \( 10^9+7 \).
sample
3 3 2
2 2
1 2
3 2
16