Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
76877219 Contestant:
nikhily.725
1337D - 57 C++14 (GCC 6-32) Accepted 140 ms 2344 KB 2020-04-15 19:17:28 2020-04-15 21:26:49
→ Source
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;

ll formula(ll x,ll y,ll z){
	ll d1=x-y;
	ll d2=y-z;
	ll d3=z-x;
	return d1*d1+d2*d2+d3*d3;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t,x,y,z;
	cin>>t;
	while(t--){
		cin>>x>>y>>z;
		ll a[x],b[y],c[z];
		for(ll i=0;i<x;i++)cin>>a[i];
		for(ll i=0;i<y;i++)cin>>b[i];
		for(ll i=0;i<z;i++)cin>>c[i];
		sort(a,a+x);
		sort(b,b+y);
		sort(c,c+z);
		ll i=0,j=0,k=0;
		ll ans=LLONG_MAX;
		while(i<x-1 || j<y-1 || k<z-1){
			ans=min(ans,formula(a[i],b[j],c[k]));
			
			ll d1=LLONG_MAX;
			ll d2=LLONG_MAX;
			ll d3=LLONG_MAX;
			if(i<x-1)d1=formula(a[i+1],b[j],c[k]);
			if(j<y-1)d2=formula(a[i],b[j+1],c[k]);
			if(k<z-1)d3=formula(a[i],b[j],c[k+1]);
			
			if(d1<=d2 && d1<=d3){
				i++;
			}
			else if(d2<=d1 && d2<=d3){
				j++;
			}
			else{
				k++;
			}
		}
		ans=min(ans,formula(a[i],b[j],c[k]));
		cout<<ans<<'\n';
	}
	
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details