#arc171e. E - Rookhopper's Tour
E - Rookhopper's Tour
Score: points
问题陈述
有一个 行 列的网格。用 表示从顶部数第 行,从左边数第 列的单元格。此外,有一个黑色棋子和 个白色棋子。 你将使用这些物品玩一个单人游戏。
以下是规则。最初,你将黑色棋子放在 。然后,你将每个 个白色棋子放在网格的某个单元格上。这里:
- 你不能将白色棋子放在 。
- 每行最多可以放一个白色棋子。
- 每列最多可以放一个白色棋子。
然后,你将执行以下操作,直到无法进行为止:
- 假设黑色棋子在 。执行以下四种操作之一:
- 如果 处有白色棋子 ,则移除那个白色棋子,并将黑色棋子移动到 。
- 如果 处有白色棋子 ,则移除那个白色棋子,并将黑色棋子移动到 。
- 如果 处有白色棋子 ,则移除那个白色棋子,并将黑色棋子移动到 。
- 如果 处有白色棋子 ,则移除那个白色棋子,并将黑色棋子移动到 。
- 这里,如果黑色棋子要移动到的单元格不存在,则不能进行这样的移动。
下面的图示说明了示例。这里,B
表示黑色棋子,W
表示白色棋子,.
表示空单元格,O
表示黑色棋子可以移动到的单元格。
..O...
..W...
......
......
..B.WO
......
如果你在完成操作时满足以下所有条件,你就赢了游戏。否则,你就输了。
- 网格上所有的白色棋子都已被移除。
- 黑色棋子放在 。
通过最佳执行操作,你可以赢得游戏的 个白色棋子的初始配置有多少种?找出模 的计数。
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a grid with rows and columns. Let denote the cell at the -th row from the top and the -th column from the left. Additionally, there is one black stone and white stones.
You will play a single-player game using these items.
Here are the rules. Initially, you place the black stone at . Then, you place each of the white stones on some cell of the grid. Here:
- You cannot place a white stone at .
- You can place at most one white stone per row.
- You can place at most one white stone per column.
Then, you will perform the following operation until you cannot do so:
- Assume the black stone is at . Perform one of the four operations below:
- If there is a white stone at where , remove that white stone and move the black stone to .
- If there is a white stone at where , remove that white stone and move the black stone to .
- If there is a white stone at where , remove that white stone and move the black stone to .
- If there is a white stone at where , remove that white stone and move the black stone to .
- Here, if the cell to which the black stone is to be moved does not exist, such a move cannot be made.
The following figure illustrates an example. Here, B
represents the black stone, W
represents a white stone, .
represents an empty cell, and O
represents a cell to which the black stone can be moved.
..O...
..W...
......
......
..B.WO
......
You win the game if all of the following conditions are satisfied when you finish performing the operation. Otherwise, you lose.
- All white stones have been removed from the grid.
- The black stone is placed at .
In how many initial configurations of the white stones can you win the game by optimally performing the operation? Find the count modulo .
Constraints
- , , , and are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the number, modulo , of possible configurations of the white stones that can lead to your victory.
Sample Input 1
6 4 2 3
Sample Output 1
4
For example, consider the white stones placed as shown in the following figure:
......
..BW..
.....W
......
..W...
....W.
Here, you can win the game by moving the black stone in the following steps:
- Remove the white stone at and move the black stone to .
- Remove the white stone at and move the black stone to .
- Remove the white stone at and move the black stone to .
- Remove the white stone at and move the black stone to .
- Since all white stones have been removed from the grid and the black stone is placed at , you win the game.
There are four configurations of white stones that can lead to your victory.
Sample Input 2
5 3 1 3
Sample Output 2
0
Sample Input 3
200000 47718 21994 98917
Sample Output 3
146958602