CF291A.Spyke Talks

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Polycarpus is the director of a large corporation. There are n secretaries working for the corporation, each of them corresponds via the famous Spyke VoIP system during the day. We know that when two people call each other via Spyke, the Spyke network assigns a unique ID to this call, a positive integer session number.

One day Polycarpus wondered which secretaries are talking via the Spyke and which are not. For each secretary, he wrote out either the session number of his call or a 0 if this secretary wasn't talking via Spyke at that moment.

Help Polycarpus analyze these data and find out the number of pairs of secretaries that are talking. If Polycarpus has made a mistake in the data and the described situation could not have taken place, say so.

Note that the secretaries can correspond via Spyke not only with each other, but also with the people from other places. Also, Spyke conferences aren't permitted — that is, one call connects exactly two people.

波利卡普斯是一家大型公司的总监。公司共有 nn 名秘书,她们在白天通过著名的 Spyke 网络电话系统进行通信。已知当两人通过 Spyke 互相通话时,Spyke 网络会为该次通话分配一个唯一的 ID——一个正整数会话编号(session number)。

某日,波利卡普斯想弄清哪些秘书正在通过 Spyke 通话、哪些没有。他为每位秘书记录下:若该秘书当时正在通过 Spyke 通话,则记下其通话的会话编号;否则记为 00。

请帮助波利卡普斯分析这些数据,并求出正在相互通话的秘书对的数量。如果波利卡普斯的数据存在错误,使得所描述的情形根本不可能发生,请指出这一点。

注意:秘书们不仅可能彼此之间通过 Spyke 通话,也可能与公司以外的其他人通话。此外,Spyke 不支持多方会议(conference)——即每次通话恰好连接两个人。

输入格式

The first line contains integer n (1 ≤ n ≤ 103) — the number of secretaries in Polycarpus's corporation. The next line contains n space-separated integers: _id_1, _id_2, ..., id__n (0 ≤ id__i ≤ 109). Number id__i equals the number of the call session of the i-th secretary, if the secretary is talking via Spyke, or zero otherwise.

Consider the secretaries indexed from 1 to n in some way.

第一行包含一个整数 $ n (( 1 \leq n \leq 10^3 $)—— 表示 Polycarpus 公司中秘书的数量。
下一行包含 $ n $ 个以空格分隔的整数:$ id_1,\ id_2,\ \dots,\ id_n (( 0 \leq id_i \leq 10^9 )。其中,)。其中, id_i $ 表示第 $ i $ 位秘书当前正在进行的通话会话编号(若该秘书正通过 Spyke 进行通话),否则为 $ 0 $。

假设秘书按某种方式被编号为 $ 1 $ 至 $ n $。

输出格式

Print a single integer — the number of pairs of chatting secretaries, or -1 if Polycarpus's got a mistake in his records and the described situation could not have taken place.

输出一个整数——聊天的秘书对的数量;如果波利卡普斯的记录有误,即所描述的情况不可能发生,则输出 −1-1。

输入输出样例

  • 输入#1

    6
    0 1 7 1 7 10

    输出#1

    2
  • 输入#2

    3
    1 1 1

    输出#2

    -1
  • 输入#3

    1
    0

    输出#3

    0

说明/提示

In the first test sample there are two Spyke calls between secretaries: secretary 2 and secretary 4, secretary 3 and secretary 5.

In the second test sample the described situation is impossible as conferences aren't allowed.

在第一个测试样例中,秘书之间存在两次 Spyke 通话:秘书 2 与秘书 4 之间,以及秘书 3 与秘书 5 之间。

在第二个测试样例中,所描述的情形不可能发生,因为不允许召开会议。

输入解题思路,AI测评打分。不知道怎么写?

首页