QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 2048 MB Puntuación total: 100

#2526. 不精确的计算机

Estadísticas

“不精确计算机”(Imprecise Computer,简称 IC)是一种存在结构性问题的计算机,它仅在两个整数之差至少为 2 时才能正确比较它们。例如,IC 总能正确回答“4 大于 2”,但对于“2 大于 3”或“3 大于 2”,它可能会给出其中任意一个回答(在这种情况下,IC 会随机选择其中一个)。对于两个整数 $x$ 和 $y$,当 IC 回答“$x$ 大于 $y$”时,我们称“$x$ 击败了 $y$”。

给定一个正整数 $n$,令 $P_n = \{1, 2, \dots, n\}$ 为从 1 到 $n$ 的正整数集合。然后我们使用 IC 在 $P_n$ 上进行双循环赛。双循环赛定义如下:

  1. 比赛由两轮组成(第 1 轮和第 2 轮)。
  2. 在每一轮中,将 $P_n$ 中的每个元素与其他所有元素进行比较。

现在,对于 $P_n$ 中的每个元素 $k$,令 $r_i(k)$ 为 $k$ 在第 $i$ 轮比赛中的胜场数。我们定义“差值序列” $D = d_1 d_2 \dots d_n$,其中对于每个 $1 \le k \le n$,$d_k = |r_1(k) - r_2(k)|$。

以下是 $n = 5$ 时的示例:

第 1 轮 第 2 轮
2 击败 1 3 击败 1
3 击败 1 4 击败 1
4 击败 1 5 击败 1
5 击败 1 1 击败 2
3 击败 2 4 击败 2
4 击败 2 5 击败 2
5 击败 2 2 击败 3
5 击败 3 4 击败 3
3 击败 4 5 击败 3
4 击败 5 5 击败 4

在上述示例中,$r_1(1) = 0, r_1(2) = 1, r_1(3) = 3, r_1(4) = 3, r_1(5) = 3$,且 $r_2(1) = 1, r_2(2) = 1, r_2(3) = 1, r_2(4) = 3, r_2(5) = 4$。因此,该示例中的差值序列为 $D = 1\ 0\ 2\ 0\ 1$。

给定一个包含 $n$ 个非负整数的序列,编写一个程序来判断该输入序列是否可能是 $P_n$ 的差值序列。

输入格式

程序从标准输入读取数据。输入的第一行包含一个整数 $n$ ($3 \le n \le 1,000,000$),表示 $P_n$ 的大小。接下来的第二行给出一个包含 $n$ 个介于 0 到 $n$ 之间的整数的序列,序列中每个元素由单个空格分隔。

输出格式

程序将结果写入标准输出。仅输出一行。如果该序列可以是 $P_n$ 的差值序列,则输出 YES,否则输出 NO

样例

样例输入 1

5
1 0 2 0 1

样例输出 1

YES

样例输入 2

5
1 1 2 1 0

样例输出 2

NO

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.