Submission #1535097


Source Code Expand

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N;
ll x[200000],y[200000];
int main(){
	cin>>N;
	int amn=0,amx=0;
	rep(i,N){
		cin>>x[i]>>y[i];
		if(x[i]>y[i]) swap(x[i],y[i]);
		if(x[amn]>x[i]) amn = i;
		if(y[amx]<y[i]) amx = i;
	}
	if(N==1){
		puts("0");
		return 0;
	}
	ll ans = 2e18;
	if(amn!=amx){	//rr
		using P = pair<ll,ll>;
		priority_queue<P,vector<P>,greater<P>> que;
		vector<bool> canmove(N,true);

		ll mx = 0;
		ll res = 2e18;
		rep(i,N){
			if(i!=amn){
				que.push(P(x[i],i));
				chmax(mx,x[i]);
			}else{
				que.push(P(y[i],i));
				chmax(mx,y[i]);
			}
		}
		canmove[amn] = canmove[amx] = false;

		while(!que.empty()){
			P p = que.top();
			que.pop();
			ll v = p.fs;
			int i = p.sc;
			chmin(res,mx-v);
			chmax(mx,y[i]);

			if(!canmove[i]) break;

			que.push(P(y[i],i));
			canmove[i] = 0;
		}
		chmin(ans,res*(y[amx]-x[amn]));
	}
	{	//(max - rmin)*(bmax - min)
		ll rmx = -2e18, rmn = 2e18, bmx = -2e18, bmn = 2e18;
		rep(i,N){
			chmax(rmx,x[i]);
			chmin(rmn,x[i]);
			chmax(bmx,y[i]);
			chmin(bmn,y[i]);
		}
		ll tmp = (rmx-rmn)*(bmx-bmn);
		chmin(ans,tmp);
	}
	cout<<ans<<endl;

}

Submission Info

Submission Time
Task E - Ball Coloring
User sigma425
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1772 Byte
Status AC
Exec Time 178 ms
Memory 9588 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 35
Set Name Test Cases
Sample example0, example1, example2
All div20, div21, div22, div23, div24, example0, example1, example2, maxrand0, maxrand1, maxrand2, maxrand20, maxrand21, maxrand210, maxrand211, maxrand22, maxrand23, maxrand24, maxrand25, maxrand26, maxrand27, maxrand28, maxrand29, maxrand3, maxrand4, smallrand0, smallrand1, smallrand2, smallrand3, smallrand4, sparse0, sparse1, sparse2, sparse3, sparse4
Case Name Status Exec Time Memory
div20 AC 165 ms 8436 KB
div21 AC 165 ms 8436 KB
div22 AC 166 ms 9332 KB
div23 AC 178 ms 8692 KB
div24 AC 165 ms 7668 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 164 ms 8692 KB
maxrand1 AC 164 ms 7796 KB
maxrand2 AC 166 ms 9332 KB
maxrand20 AC 161 ms 8564 KB
maxrand21 AC 172 ms 8436 KB
maxrand210 AC 167 ms 7924 KB
maxrand211 AC 170 ms 9460 KB
maxrand22 AC 168 ms 7924 KB
maxrand23 AC 171 ms 8436 KB
maxrand24 AC 173 ms 8948 KB
maxrand25 AC 172 ms 8820 KB
maxrand26 AC 169 ms 7924 KB
maxrand27 AC 169 ms 8820 KB
maxrand28 AC 170 ms 9204 KB
maxrand29 AC 170 ms 8308 KB
maxrand3 AC 164 ms 9588 KB
maxrand4 AC 167 ms 7796 KB
smallrand0 AC 1 ms 256 KB
smallrand1 AC 1 ms 256 KB
smallrand2 AC 1 ms 256 KB
smallrand3 AC 1 ms 256 KB
smallrand4 AC 1 ms 256 KB
sparse0 AC 163 ms 8436 KB
sparse1 AC 164 ms 9588 KB
sparse2 AC 164 ms 7668 KB
sparse3 AC 165 ms 8308 KB
sparse4 AC 165 ms 7796 KB