No.99 Jumping Pieces
Problem Statement
There are $N$ pieces at integer coordinates on a one-dimensional number line.
The initial coordinates of the pieces are pairwise distinct and are $X_1,X_2,\ldots,X_N$.
In $1$ operation, you can move $1$ piece: if its current coordinate is $x$, it can move to $x+2$ or $x-2$.
However, such a move is not allowed if there is already a piece at the destination. Also, if a piece jumps over another piece while moving, both the jumping piece and the piece jumped over disappear.
You want to minimize the number of pieces.
Write a program that finds the minimum possible number of pieces remaining at the end, given that you may perform any number of operations.
Input
$N$ $X_1$ $X_2$ $\cdots$ $X_N$
$1 \leq N \leq 10^5$
$-10^9 \leq X_k \leq 10^9$
Output
Output the minimum number of remaining pieces on $1$ line.
Print a newline at the end.
Sample
Sample 1
Input
4 1 2 4 3
Output
0
If the piece at coordinate $2$ jumps over the piece at coordinate $1$, and then the piece at coordinate $4$ jumps over the piece at coordinate $3$, all the pieces disappear.
Sample 2
Input
10 -746 0 11 98 1 14 998 123 837 15
Output
0
Apparently, if you do things well somehow, all of them disappear.
Sample 3
Input
5 1000000000 -1000000000 0 987654321 -123456789
Output
1
Since pieces disappear in sets of $2$, $1$ piece inevitably remains at the end.
Also, it is possible to make $4$ pieces disappear.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
LayCurse