CF1336B.Xenia and Colorful Gems

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself.

Recently Xenia has bought nrn_r red gems, ngn_g green gems and nbn_b blue gems. Each of the gems has a weight.

Now, she is going to pick three gems.

Xenia loves colorful things, so she will pick exactly one gem of each color.

Xenia loves balance, so she will try to pick gems with little difference in weight.

Specifically, supposing the weights of the picked gems are xx, yy and zz, Xenia wants to find the minimum value of (x−y)2+(y−z)2+(z−x)2(x-y)^2+(y-z)^2+(z-x)^2. As her dear friend, can you help her?

Xenia 是一位出身贵族的女孩。由于家庭的刻板与严苛,Xenia 不得不寻找一些方式来自我娱乐。

最近,Xenia 购买了 nrn_r 颗红色宝石、ngn_g 颗绿色宝石和 nbn_b 颗蓝色宝石。每颗宝石都有一个重量。

现在,她将从中挑选三颗宝石。

Xenia 喜爱色彩缤纷的事物,因此她将恰好从每种颜色中各挑选一颗宝石。

Xenia 喜爱平衡,因此她会尽量挑选重量差异较小的宝石。

具体而言,假设所选三颗宝石的重量分别为 xx、yy 和 zz,Xenia 希望最小化 (x−y)2+(y−z)2+(z−x)2(x-y)^2+(y-z)^2+(z-x)^2 的值。作为她亲爱的朋友,你能帮她实现这一目标吗?

输入格式

The first line contains a single integer tt (1≤t≤1001\le t \le 100) — the number of test cases. Then tt test cases follow.

The first line of each test case contains three integers nr,ng,nbn_r,n_g,n_b (1≤nr,ng,nb≤1051\le n_r,n_g,n_b\le 10^5) — the number of red gems, green gems and blue gems respectively.

The second line of each test case contains nrn_r integers r1,r2,…,rnrr_1,r_2,\ldots,r_{n_r} (1≤ri≤1091\le r_i \le 10^9) — rir_i is the weight of the ii-th red gem.

The third line of each test case contains ngn_g integers g1,g2,…,gngg_1,g_2,\ldots,g_{n_g} (1≤gi≤1091\le g_i \le 10^9) — gig_i is the weight of the ii-th green gem.

The fourth line of each test case contains nbn_b integers b1,b2,…,bnbb_1,b_2,\ldots,b_{n_b} (1≤bi≤1091\le b_i \le 10^9) — bib_i is the weight of the ii-th blue gem.

It is guaranteed that ∑nr≤105\sum n_r \le 10^5, ∑ng≤105\sum n_g \le 10^5, ∑nb≤105\sum n_b \le 10^5 (the sum for all test cases).

第一行包含一个整数 tt(1≤t≤1001\le t \le 100)—— 表示测试用例的数量。随后是 tt 个测试用例。

每个测试用例的第一行包含三个整数 nr,ng,nbn_r,n_g,n_b(1≤nr,ng,nb≤1051\le n_r,n_g,n_b\le 10^5)—— 分别表示红色宝石、绿色宝石和蓝色宝石的数量。

每个测试用例的第二行包含 nrn_r 个整数 r1,r2,…,rnrr_1,r_2,\ldots,r_{n_r}(1≤ri≤1091\le r_i \le 10^9)—— 其中 rir_i 表示第 ii 颗红色宝石的重量。

每个测试用例的第三行包含 ngn_g 个整数 g1,g2,…,gngg_1,g_2,\ldots,g_{n_g}(1≤gi≤1091\le g_i \le 10^9)—— 其中 gig_i 表示第 ii 颗绿色宝石的重量。

每个测试用例的第四行包含 nbn_b 个整数 b1,b2,…,bnbb_1,b_2,\ldots,b_{n_b}(1≤bi≤1091\le b_i \le 10^9)—— 其中 bib_i 表示第 ii 颗蓝色宝石的重量。

保证对所有测试用例,有 ∑nr≤105\sum n_r \le 10^5、∑ng≤105\sum n_g \le 10^5、∑nb≤105\sum n_b \le 10^5(即各颜色宝石数量的总和均不超过 10510^5)。

输出格式

For each test case, print a line contains one integer — the minimum value which Xenia wants to find.

对于每个测试用例,输出一行,包含一个整数——Xenia 想要求的最小值。

输入输出样例

  • 输入#1

    5
    2 2 3
    7 8
    6 3
    3 1 4
    1 1 1
    1
    1
    1000000000
    2 2 2
    1 2
    5 4
    6 7
    2 2 2
    1 2
    3 4
    6 7
    3 4 1
    3 2 1
    7 3 3 4
    6

    输出#1

    14
    1999999996000000002
    24
    24
    14

说明/提示

In the first test case, Xenia has the following gems:

If she picks the red gem with weight 77, the green gem with weight 66, and the blue gem with weight 44, she will achieve the most balanced selection with (x−y)2+(y−z)2+(z−x)2=(7−6)2+(6−4)2+(4−7)2=14(x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14.

在第一个测试用例中,Xenia 拥有以下宝石:

如果她选择重量为 77 的红色宝石、重量为 66 的绿色宝石以及重量为 44 的蓝色宝石,则可得到最均衡的选择,此时 (x−y)2+(y−z)2+(z−x)2=(7−6)2+(6−4)2+(4−7)2=14(x-y)^2+(y-z)^2+(z-x)^2=(7-6)^2+(6-4)^2+(4-7)^2=14。

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

首页