Submission #1533089


Source Code Expand

#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

ll mainmain(){
	int n;
	cin>>n;
	vector<pll> v(n);
	rep(i,n){
		cin>>v[i].fi>>v[i].se;
		if(v[i].fi > v[i].se) swap(v[i].fi, v[i].se);
	}
	sort(ALL(v));
	if(n==1){
		return 0;
	}
	ll mn = INFL, mx = 0;
	int pmn = -1, pmx = -1;
	rep(i,n){
		if(mn > v[i].fi){
			mn = v[i].fi;
			pmn = i;
		}
		if(mx < v[i].se){
			mx = v[i].se;
			pmx = i;
		}
	}
	// cout<<mx<<" "<<pmx<<endl;
	// cout<<mn<<" "<<pmn<<endl;
	ll a = 0;
	ll b = INFL;
	if(pmn==pmx){
		v.erase(v.begin()+pmn);
	}
	else{
		a = v[pmx].fi;
		b = v[pmn].se;
		v.erase(v.begin()+max(pmn,pmx));
		v.erase(v.begin()+min(pmn,pmx));
	}
	// cout<<v.size()<<endl;
	ll aa = a, bb = b;
	rep(i,v.size()){
		maxs(a, v[i].fi);
		mins(b, v[i].se);
	}
	ll ans = (a-mn)*(mx-b);
	if(pmn == pmx || v.size()==0){
		return ans;
	}
	// cout<<a<<" "<<b<<endl;
	a = aa;
	b = bb;
	vll wfi(v.size());
	vll wse(v.size());
	ll tmx = 0;
	for(int i=wfi.size()-1; i>=0; i--){
		maxs(tmx, v[i].fi);
		wfi[i] = tmx;
	}
	ll tmn = INFL;
	rep(i,wfi.size()){
		mins(tmn, v[i].se);
		wse[i] = tmn;
	}
	rep(i,v.size()){
		ll l = min(b, v[i].fi);
		ll r = max(a, wfi[i]);
		mins(ans, (mx-mn)*(r-l));
		mins(b, v[i].se);
		maxs(a, v[i].se);
	}
	a = aa;
	b = bb;
	for(int i=wfi.size()-1; i>=0; i--){
		ll l = min(b, wse[i]);
		ll r = max(a, v[i].se);
		mins(ans, (mx-mn)*(r-l));
		mins(b, v[i].fi);
		maxs(a, v[i].fi);
	}
	return ans;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    cout<<mainmain()<<endl;
}

Submission Info

Submission Time
Task E - Ball Coloring
User j_gui0121
Language C++14 (GCC 5.4.1)
Score 0
Code Size 3627 Byte
Status WA
Exec Time 62 ms
Memory 6528 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 700
Status
AC × 3
AC × 19
WA × 16
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 58 ms 6528 KB
div21 AC 58 ms 6528 KB
div22 WA 60 ms 6528 KB
div23 WA 58 ms 6528 KB
div24 WA 58 ms 6528 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 WA 58 ms 6528 KB
maxrand1 AC 59 ms 6528 KB
maxrand2 WA 59 ms 6528 KB
maxrand20 AC 62 ms 6528 KB
maxrand21 AC 61 ms 6528 KB
maxrand210 AC 61 ms 6528 KB
maxrand211 AC 61 ms 6528 KB
maxrand22 AC 62 ms 6528 KB
maxrand23 AC 61 ms 6528 KB
maxrand24 AC 60 ms 6528 KB
maxrand25 AC 61 ms 6528 KB
maxrand26 AC 62 ms 6528 KB
maxrand27 AC 61 ms 6528 KB
maxrand28 AC 61 ms 6528 KB
maxrand29 WA 60 ms 6528 KB
maxrand3 WA 59 ms 6528 KB
maxrand4 WA 59 ms 6528 KB
smallrand0 WA 1 ms 256 KB
smallrand1 AC 1 ms 256 KB
smallrand2 WA 1 ms 256 KB
smallrand3 AC 1 ms 256 KB
smallrand4 WA 1 ms 256 KB
sparse0 WA 59 ms 6528 KB
sparse1 WA 58 ms 6528 KB
sparse2 WA 59 ms 6528 KB
sparse3 WA 59 ms 6528 KB
sparse4 WA 59 ms 6528 KB