#abc377c. C - Avoid Knight Attack
C - Avoid Knight Attack
Score : points
问题陈述
有一个由 个方格组成的网格,其中包含 行和 列。用 表示从顶部数第 行()和从左边数第 列()的方格。
每个方格要么是空的,要么上面放置了一个棋子。网格上放置了 个棋子,第 个()棋子放置在方格 上。
你想要在一个空方格上放置你的棋子,使得它不能被任何现有的棋子捕获。
放置在方格 上的棋子可以捕获满足以下任一条件的棋子:
- 放置在方格
- 放置在方格
- 放置在方格
- 放置在方格
- 放置在方格
- 放置在方格
- 放置在方格
- 放置在方格
在这里,涉及不存在的方格的条件被认为是永远不会满足的。
例如,放置在方格 上的棋子可以捕获下图中蓝色方格上的棋子:
你可以在多少个方格上放置你的棋子?
以上为大语言模型 kimi 翻译,仅供参考。
Problem Statement
There is a grid of squares with rows and columns. Let denote the square at the -th row from the top and -th column from the left .
Each square is either empty or has a piece placed on it. There are pieces placed on the grid, and the -th piece is placed on square .
You want to place your piece on an empty square in such a way that it cannot be captured by any of the existing pieces.
A piece placed on square can capture pieces that satisfy any of the following conditions:
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
- Placed on square
Here, conditions involving non-existent squares are considered to never be satisfied.
For example, a piece placed on square can capture pieces placed on the squares shown in blue in the following figure:
How many squares can you place your piece on?
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the number of empty squares where you can place your piece without it being captured by any existing pieces.
Sample Input 1
8 6
1 4
2 1
3 8
4 5
5 2
8 3
Sample Output 1
38
The existing pieces can capture pieces placed on the squares shown in blue in the following figure:
Therefore, you can place your piece on the remaining squares.
Sample Input 2
1000000000 1
1 1
Sample Output 2
999999999999999997
Out of squares, only squares cannot be used: squares , , and .
Note that the answer may be or greater.
Sample Input 3
20 10
1 4
7 11
7 15
8 10
11 6
12 5
13 1
15 2
20 10
20 15
Sample Output 3
338