#abc377f. F - Avoid Queen Attack
F - Avoid Queen 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 in row
- Placed in column
- Placed on any square where
- Placed on any square where
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
2
The existing pieces can capture pieces placed on the squares shown in blue in the following figure:
Therefore, you can place your piece on only two squares: squares and .
Sample Input 2
1000000000 1
1 1
Sample Output 2
999999997000000002
Out of squares, the squares that cannot be used are: squares in row , squares in column , and squares , , , , totaling squares.
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
77