CF1788D.Moving Dots

普及+/提高

通过率:0%

时间限制:1.50s

内存限制:1024MB

AC君温馨提醒

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

题目描述

We play a game with nn dots on a number line.

The initial coordinate of the ii-th dot is xix_i. These coordinates are distinct. Every dot starts moving simultaneously with the same constant speed.

Each dot moves in the direction of the closest dot (different from itself) until it meets another dot. In the case of a tie, it goes to the left. Two dots meet if they are in the same coordinate, after that, they stop moving.

After enough time, every dot stops moving. The result of a game is the number of distinct coordinates where the dots stop.

Because this game is too easy, calculate the sum of results when we play the game for every subset of the given nn dots that has at least two dots. As the result can be very large, print the sum modulo 109+710^9+7.

我们在一条数轴上有 nn 个点进行一个游戏。

第 ii 个点的初始坐标为 xix_i,这些坐标互不相同。每个点同时以相同的恒定速度开始运动。

每个点均朝向离它最近的(且不同于自身的)点移动,直至与另一个点相遇。若存在多个距离相等的最近点,则向左移动。当两个点到达同一坐标时即视为相遇,此后它们停止运动。

经过足够长的时间后,所有点均停止运动。游戏的结果定义为所有点最终停止位置中不同坐标的个数。

由于该游戏过于简单,请计算:对给定的 nn 个点的每一个至少包含两个点的子集,分别进行上述游戏,并将所有游戏结果求和。由于结果可能非常大,请输出该和对 109+710^9+7 取模的值。

输入格式

The first line contains one integer nn (2≤n≤30002 \leq n \leq 3000).

The next line contains nn integers x1,x2,…,xnx_1, x_2, \ldots, x_n (1≤x1<x2<…<xn≤1091 \leq x_1 \lt x_2 \lt \ldots \lt x_n \leq 10^9), where xix_i represents the initial coordinate of ii-th dot.

第一行包含一个整数 nn(2≤n≤30002 \leq n \leq 3000)。

第二行包含 nn 个整数 x1,x2,…,xnx_1, x_2, \ldots, x_n(1≤x1<x2<…<xn≤1091 \leq x_1 \lt x_2 \lt \ldots \lt x_n \leq 10^9),其中 xix_i 表示第 ii 个点的初始坐标。

输出格式

Print the sum of results modulo 109+710^9+7.

输出结果之和对 109+710^9+7 取模的值。

输入输出样例

  • 输入#1

    4
    1 2 4 6

    输出#1

    11
  • 输入#2

    5
    1 3 5 11 15

    输出#2

    30

说明/提示

In the first example, for a subset of size 22, two dots move toward each other, so there is 11 coordinate where the dots stop.

For a subset of size 33, the first dot and third dot move toward the second dot, so there is 11 coordinate where the dots stop no matter the direction where the second dot moves.

For [1,2,4,6][1, 2, 4, 6], the first and second dots move toward each other. For the third dot, initially, the second dot and the fourth dot are the closest dots. Since it is a tie, the third dot moves left. The fourth dot also moves left. So there is 11 coordinate where the dots stop, which is 1.51.5.

Because there are 66 subsets of size 22, 44 subsets of size 33 and one subset of size 44, the answer is 6⋅1+4⋅1+1=116 \cdot 1 + 4 \cdot 1 + 1 = 11.

In the second example, for a subset of size 55 (when there are dots at 11, 33, 55, 1111, 1515), dots at 11 and 1111 will move right and dots at 33, 55, 1515 will move left. Dots at 11, 33, 55 will eventually meet at 22, and dots at 1111 and 1515 will meet at 1313, so there are 22 coordinates where the dots stop.

在第一个例子中,对于大小为 22 的子集,两个点彼此相向移动,因此存在 11 个点停止的坐标。

对于大小为 33 的子集,第一个点和第三个点均向第二个点移动,因此无论第二个点朝哪个方向移动,最终都只有 11 个点停止的坐标。

对于 [1,2,4,6][1, 2, 4, 6],第一个点和第二个点彼此相向移动。对于第三个点,初始时第二个点和第四个点是距离它最近的点;由于距离相等(平局),第三个点向左移动。第四个点也向左移动。因此,点最终停止于唯一坐标 1.51.5,即存在 11 个停止坐标。

由于共有 66 个大小为 22 的子集、44 个大小为 33 的子集以及 11 个大小为 44 的子集,答案为 6⋅1+4⋅1+1=116 \cdot 1 + 4 \cdot 1 + 1 = 11。

在第二个例子中,对于大小为 55 的子集(点位于 11、33、55、1111、1515 处),位于 11 和 1111 的点向右移动,而位于 33、55、1515 的点向左移动。位于 11、33、55 的点最终将在 22 处相遇,位于 1111 和 1515 的点将在 1313 处相遇,因此共有 22 个点停止的坐标。

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

首页