CF1805F1.Survival of the Weakest (easy version)
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
This is the easy version of the problem. It differs from the hard one only in constraints on n. You can make hacks only if you lock both versions.
Let a1,a2,…,an be an array of non-negative integers. Let F(a1,a2,…,an) be the sorted in the non-decreasing order array of n−1 smallest numbers of the form ai+aj, where 1≤i<j≤n. In other words, F(a1,a2,…,an) is the sorted in the non-decreasing order array of n−1 smallest sums of all possible pairs of elements of the array a1,a2,…,an. For example, F(1,2,5,7)=[1+2,1+5,2+5]=[3,6,7].
You are given an array of non-negative integers a1,a2,…,an. Determine the single element of the array n−1F(F(F…F(a1,a2,…,an)…)). Since the answer can be quite large, output it modulo 109+7.
这是该问题的简单版本。它与困难版本的唯一区别在于对 n 的约束条件。你只有在同时锁定两个版本的情况下才能进行 hack。
设 a1,a2,…,an 是一个非负整数数组。令 F(a1,a2,…,an) 表示所有形如 ai+aj(其中 1≤i<j≤n)的 n−1 个最小数值按非递减顺序排列所得的数组。换言之,F(a1,a2,…,an) 是数组 a1,a2,…,an 中所有可能元素对之和中最小的 n−1 个和,按非递减顺序排列所得的数组。例如,F(1,2,5,7)=[1+2,1+5,2+5]=[3,6,7]。
给定一个非负整数数组 a1,a2,…,an,求经过 n−1 次嵌套应用函数 F 后所得数组的唯一元素,即 n−1F(F(F…F(a1,a2,…,an)…))。由于答案可能非常大,请输出其对 109+7 取模的结果。
输入格式
The first line contains one integer n (2≤n≤3000) — the initial length of the array.
The second line contains n integers a1,a2,…,an (0≤ai≤109) — the array elements.
第一行包含一个整数 n(2≤n≤3000)—— 数组的初始长度。
第二行包含 n 个整数 a1,a2,…,an(0≤ai≤109)—— 数组的元素。
输出格式
Output a single number — the answer modulo 109+7.
输出一个整数——答案对 109+7 取模的结果。
输入输出样例
输入#1
5 1 2 4 5 6
输出#1
34
输入#2
9 1 1 1 7 7 7 9 9 9
输出#2
256
输入#3
7 1 7 9 2 0 0 9
输出#3
20
输入#4
3 1000000000 1000000000 777
输出#4
1540
说明/提示
In the first test, the array is transformed as follows: [1,2,4,5,6]→[3,5,6,6]→[8,9,9]→[17,17]→[34]. The only element of the final array is 34.
In the second test, F(a1,a2,…,an) is [2,2,2,8,8,8,8,8]. This array is made up of 3 numbers of the form 1+1 and 5 numbers of the form 1+7.
In the fourth test, the array is transformed as follows: [109,109,777]→[109+777,109+777]→[2⋅109+1554]. 2⋅109+1554 modulo 109+7 equals 1540.
在第一次测试中,数组的变换过程如下:[1,2,4,5,6]→[3,5,6,6]→[8,9,9]→[17,17]→[34]。最终数组的唯一元素为 34。
在第二次测试中,F(a1,a2,…,an) 是 [2,2,2,8,8,8,8,8]。该数组由 3 个形如 1+1 的数和 5 个形如 1+7 的数构成。
在第四次测试中,数组的变换过程如下:[109,109,777]→[109+777,109+777]→[2⋅109+1554]。2⋅109+1554 对 109+7 取模的结果为 1540。
输入解题思路,AI测评打分。不知道怎么写?