시간 제한메모리 제한제출정답맞힌 사람정답 비율
3 초 (추가 시간 없음) 1024 MB444100.000%

문제

Everyone knows that in the game chess, a bishop moves diagonally. Boring! Consider a new piece called a cardinal. A cardinal moves diagonally, like a bishop but they are clumsy. If its movement brings a cardinal adjacent to another piece, it trips and falls on the other piece. This results in the other piece being captured and removed from the board. The cardinal that was moving then rests on the captured piece’s square. Note two squares are adjacent if they share a side, meaning they are directly horizontal or vertical from one another. A cardinal can also capture pieces like a bishop if the other piece lies on the same diagonal. A cardinal can only move if the movement results in the capture of another piece.

In this problem, you are given the initial locations of cardinal pieces on an infinite chessboard. Determine the minimum number of cardinals that remain on the board under some sequence of valid moves.

Figure 1: Illustration of a sequence of moves for sample input 3 that reduces the number of cardinals to 3. Step 1: Move the cardinal at $(1,2)$ to capture the cardinal at $(3,4$). Step 2: Move the cardinal at $(1,0)$ to capture the cardinal at $(7,5)$. That is, the moving cardinal “trips” beside the cardinal at $(7,5)$ and captures it. Step 3: Move the cardinal that is currently at $(3,4)$ to capture the cardinal at $(1,7)$. Step 4: Move the cardinal at $(7,1)$ to capture the cardinal at $(1,7)$. Note at this time there is no cardinal at $(3,4)$ so we move the cardinal past this square without “tripping” onto it. The final squares with cardinals are $(1,7)$, $(3,7)$, and $(7,5)$ and we cannot move any remaining cardinal to capture another cardinal.

입력

The first line of input contains a single integer $N$ ($1≤N≤10^5$), which is the number of cardinal pieces to consider.

The next line contains $2N$ space-separated integers $r_1,c_1,r_2,c_2,\dots ,r_N,c_N$ ($10^{-9}≤r_i,c_i≤10^9$). These give the initial cardinal locations, so cardinal $i$ initially lies on square $(r_i,c_i)$. Furthermore, $|r_i-r_j|≥2$ or $|c_i-c_j|≥2$ (or both) for any $1≤i<j≤N$.

출력

Display the minimum number of cardinals that remain on the board though some sequence of valid moves.

예제 입력 1

3
-1 0 4 4 7 1

예제 출력 1

1

예제 입력 2

4
0 0 4 4 10 12 30 -7

예제 출력 2

2

예제 입력 3

7
1 0 1 2 1 7 3 4 3 7 7 1 7 5

예제 출력 3

3

출처

University > University of Alberta Programming Contest > UAPC 2022 C번

  • 문제를 만든 사람: Zachary Friggstad