Score : 500 points
问题描述
令 N 为一个正整数。我们有一个 (2N+1)×(2N+1) 的网格,其中行编号从0到2N,列编号也从0到2N。用 (i,j) 表示第 i 行和第 j 列的方格。
我们有一个白色兵(pawn),它最初位于 (0,N)。另外,我们有 M 个黑色兵,其中第 i 个位于 (Xi,Yi)。
当白色兵位于 (i,j) 时,你可以执行以下操作之一来移动它:
- 如果满足 0≤i≤2N−1 和 0≤j≤2N,且 (i+1,j) 不包含 黑色兵,则将白色兵移动到 (i+1,j)。
- 如果满足 0≤i≤2N−1 和 0≤j≤2N−1,且 (i+1,j+1) 包含 黑色兵,则将白色兵移动到 (i+1,j+1)。
- 如果满足 0≤i≤2N−1 和 1≤j≤2N,且 (i+1,j−1) 包含 黑色兵,则将白色兵移动到 (i+1,j−1)。
你不能移动黑色兵。
找出通过重复这些操作可以使白色兵到达 (2N,Y) 的 Y 值的数量。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
Let N be a positive integer. We have a (2N+1)×(2N+1) grid where rows are numbered 0 through 2N and columns are also numbered 0 through 2N. Let (i,j) denote the square at Row i and Column j.
We have one white pawn, which is initially at (0,N). Also, we have M black pawns, the i-th of which is at (Xi,Yi).
When the white pawn is at (i,j), you can do one of the following operations to move it:
- If 0≤i≤2N−1, 0≤j≤2N hold and (i+1,j) does not contain a black pawn, move the white pawn to (i+1,j).
- If 0≤i≤2N−1, 0≤j≤2N−1 hold and (i+1,j+1) does contain a black pawn, move the white pawn to (i+1,j+1).
- If 0≤i≤2N−1, 1≤j≤2N hold and (i+1,j−1) does contain a black pawn, move the white pawn to (i+1,j−1).
You cannot move the black pawns.
Find the number of integers Y such that it is possible to have the white pawn at (2N,Y) by repeating these operations.
Constraints
- 1≤N≤109
- 0≤M≤2×105
- 1≤Xi≤2N
- 0≤Yi≤2N
- (Xi,Yi)=(Xj,Yj) (i=j)
- All values in input are integers.
Input is given from Standard Input in the following format:
N M
X1 Y1
:
XM YM
Output
Print the answer.
2 4
1 1
1 2
2 0
4 2
Sample Output 1
3
We can move the white pawn to (4,0), (4,1), and (4,2), as follows:
- (0,2)→(1,1)→(2,1)→(3,1)→(4,2)
- (0,2)→(1,1)→(2,1)→(3,1)→(4,1)
- (0,2)→(1,1)→(2,0)→(3,0)→(4,0)
On the other hand, we cannot move it to (4,3) or (4,4). Thus, we should print 3.
1 1
1 1
Sample Output 2
0
We cannot move the white pawn from (0,1).
update @ 2024/3/10 09:16:24