305217: CF992A. Nastya and an Array
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Nastya and an Array
题意翻译
## 题目描述 $Nastya$ 拥有一个大小为 $n$ 的数组。一次操作可以将数组中所有非零的数字全部加上一个整数(可以为负)。求至少要多少次操作才能将数组中的数全部变成 $0$ 。 ## 输入格式 第 $1$ 行,有 $1$ 个整数,表示数组的大小 $n$ 。 (数据范围: $1 \leqslant n \leqslant 10^5$ ) 第 $2$ 行,有 $n$ 个整数,表示数组的元素 $a_i$ 。 (数据范围: $-10^5 \leqslant a_i \leqslant 10^5$ ) ##输出格式 仅 $1$ 个整数,表示至少要进行多少次操作。 ##提示与说明 - 第 $1$ 组样例的解释: 只要进行一次操作,将所有元素加上 $-1$ ,数组中的数就可以全部变成 $0$ 。 - 第 $2$ 组样例的解释: 可以先将所有非零元素加上 $-2$ ,得到 ${0,\ 0,\ -3}$ 。接下来只要再将所有非零元素加上 $3$ ,就可以得到 ${0,\ 0,\ 0}$ 。 感谢@Sooke 提供翻译题目描述
Nastya owns too many arrays now, so she wants to delete the least important of them. However, she discovered that this array is magic! Nastya now knows that the array has the following properties: - In one second we can add an arbitrary (possibly negative) integer to all elements of the array that are not equal to zero. - When all elements of the array become equal to zero, the array explodes. Nastya is always busy, so she wants to explode the array as fast as possible. Compute the minimum time in which the array can be exploded.输入输出格式
输入格式
The first line contains a single integer $ n $ ( $ 1<=n<=10^{5} $ ) — the size of the array. The second line contains $ n $ integers $ a_{1},a_{2},...,a_{n} $ ( $ -10^{5}<=a_{i}<=10^{5} $ ) — the elements of the array.
输出格式
Print a single integer — the minimum number of seconds needed to make all elements of the array equal to zero.
输入输出样例
输入样例 #1
5
1 1 1 1 1
输出样例 #1
1
输入样例 #2
3
2 0 -1
输出样例 #2
2
输入样例 #3
4
5 -6 -5 1
输出样例 #3
4