1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| #include <iostream> #include <algorithm> #include <cstring> #include <cstdio> #include <vector>
template <class T> inline void read(T &x) { x = 0; int f = 0; char ch = getchar(); while (!isdigit(ch)) { f |= ch == '-'; ch = getchar(); } while (isdigit(ch)) { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } x = f ? -x : x; return; }
typedef long long LL;
std::vector<LL> r, g, b; LL ans, nr, ng, nb, t, p;
void solve(std::vector<LL> a, std::vector<LL> b, std::vector<LL> c) { for (auto x : a) { auto y = std::lower_bound(b.begin(), b.end(), x), z = std::upper_bound(c.begin(), c.end(), x); if (y == b.end() || z == c.begin()) continue; --z; ans = std::min(ans, (x - *y) * (x - *y) + (*y - *z) * (*y - *z) + (x - *z) * (x - *z)); } }
int main() { read(t); while (t--) { ans = 9e18; r.clear(), g.clear(), b.clear(); read(nr), read(ng), read(nb); for (int i = 1; i <= nr; ++i) read(p), r.push_back(p); for (int i = 1; i <= ng; ++i) read(p), g.push_back(p); for (int i = 1; i <= nb; ++i) read(p), b.push_back(p); std::sort(r.begin(), r.end()), std::sort(g.begin(), g.end()), std::sort(b.begin(), b.end()); solve(r, g, b), solve(r, b, g), solve(g, r, b), solve(g, b, r), solve(b, r, g), solve(b, g, r); printf("%lld\n", ans); } return 0; }
|