CF1806C.Sequence Master
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For some positive integer m, YunQian considers an array q of 2m (possibly negative) integers good, if and only if for every possible subsequence of q that has length m, the product of the m elements in the subsequence is equal to the sum of the m elements that are not in the subsequence. Formally, let U=1,2,…,2m. For all sets S⊆U such that ∣S∣=m, i∈S∏qi=i∈U∖S∑qi.
Define the distance between two arrays a and b both of length k to be i=1∑k∣ai−bi∣.
You are given a positive integer n and an array p of 2n integers.
Find the minimum distance between p and q over all good arrays q of length 2n. It can be shown for all positive integers n, at least one good array exists. Note that you are not required to construct the array q that achieves this minimum distance.
对于某个正整数 m,云茜称一个长度为 2m 的(可能含负数的)整数数组 q 是“好的”,当且仅当:对 q 的任意一个长度为 m 的子序列,该子序列中 m 个元素的乘积等于其余 m 个不在该子序列中的元素之和。形式化地,令 U={1,2,…,2m}。对所有满足 ∣S∣=m 的集合 S⊆U,均有
i∈S∏qi=i∈U∖S∑qi.
定义两个长度均为 k 的数组 a 和 b 之间的距离为 i=1∑k∣ai−bi∣。
现给定一个正整数 n 和一个长度为 2n 的整数数组 p。
求 p 与所有长度为 2n 的“好”数组 q 之间的最小距离。可以证明:对任意正整数 n,至少存在一个“好”数组。注意:你无需构造出达到该最小距离的数组 q。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer n (1≤n≤2⋅105).
The second line of each test case contains 2n integers p1,p2,…,p2n (∣pi∣≤109).
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含一个整数 n(1≤n≤2⋅105)。
每个测试用例的第二行包含 2n 个整数 p1,p2,…,p2n(∣pi∣≤109)。
保证所有测试用例的 n 值之和不超过 2⋅105。
输出格式
For each test case, output the minimum distance between p and a good q.
对于每个测试用例,输出点 p 与一个“好”点 q 之间的最小距离。
输入输出样例
输入#1
4 1 6 9 2 1 2 2 1 2 -2 -2 2 2 4 -3 -2 -1 0 1 2 3 4
输出#1
3 2 5 13
说明/提示
In the first test case, it is optimal to let q=[6,6].
In the second test case, it is optimal to let q=[2,2,2,2].
在第一个测试用例中,令 q=[6,6] 是最优的。
在第二个测试用例中,令 q=[2,2,2,2] 是最优的。
输入解题思路,AI测评打分。不知道怎么写?