Submission #3218545


Source Code Expand

#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=2e5;
int N;
typedef pair<ll,ll> P;
P bal[MAX_N*2];
int main(){
	cin>>N;
	ll ans=1e18;
	ll ma,mi;
	{
		set<ll> sr,sb;
		REP(i,N){
			ll x,y;
			cin>>x>>y;
			if (x>y){
				swap(x,y);
			}
			sr.insert(x);
			sb.insert(y);
			bal[i*2]=P(x,y);
			bal[i*2+1]=P(y,0);
		}
		ll rmi,rma,bmi,bma;
		auto ite=sr.begin();
		rmi=*ite;
		ite=sr.end();
		ite--;
		rma=*ite;
		ite=sb.begin();
		bmi=*ite;
		ite=sb.end();
		ite--;
		bma=*ite;
		ans=min(ans,(rma-rmi)*(bma-bmi));
		mi=rmi;
		ma=bma;
	}
	sort(bal,bal+N*2);
	{
		priority_queue<ll> pque;
		REP(i,N*2){
			if (bal[i].second!=0){
				pque.push(bal[i].first);
			}
		}
		REP(i,N*2){
			ans=min(ans,(ma-mi)*(pque.top()-bal[i].first));
			if (bal[i].second!=0){
				pque.push(bal[i].second);
			}else{
				break;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Submission Info

Submission Time
Task E - Ball Coloring
User addeight
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1018 Byte
Status AC
Exec Time 456 ms
Memory 25216 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 447 ms 25216 KB
div21 AC 449 ms 25216 KB
div22 AC 453 ms 25216 KB
div23 AC 439 ms 25216 KB
div24 AC 424 ms 25216 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 430 ms 25216 KB
maxrand1 AC 420 ms 25216 KB
maxrand2 AC 406 ms 25216 KB
maxrand20 AC 296 ms 15872 KB
maxrand21 AC 294 ms 17920 KB
maxrand210 AC 296 ms 15872 KB
maxrand211 AC 292 ms 15872 KB
maxrand22 AC 320 ms 15872 KB
maxrand23 AC 322 ms 16000 KB
maxrand24 AC 401 ms 20864 KB
maxrand25 AC 303 ms 15872 KB
maxrand26 AC 303 ms 15872 KB
maxrand27 AC 324 ms 15872 KB
maxrand28 AC 329 ms 16512 KB
maxrand29 AC 382 ms 20480 KB
maxrand3 AC 456 ms 25216 KB
maxrand4 AC 425 ms 25216 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 203 ms 8692 KB
sparse1 AC 202 ms 8692 KB
sparse2 AC 205 ms 8692 KB
sparse3 AC 203 ms 8692 KB
sparse4 AC 205 ms 8692 KB