Submission #2235128


Source Code Expand

#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

template<typename T> void Chkmax(T &x, const T &y) { x = x > y ? x : y; }
template<typename T> void Chkmin(T &x, const T &y) { x = x < y ? x : y; }

namespace io
{
	const int maxb = 1 << 15;
	char b[maxb], *s = b, *t = b;
	bool Getchar(char &ch)
	{
		return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++;
	}
}

int Getint()
{
	using namespace io;
	char ch;
	while (Getchar(ch) && (ch < '0' || ch > '9'));
	int s = ch - '0';
	while (Getchar(ch) && ch >= '0' && ch <= '9')
		s = s * 10 + ch - '0';
	return s;
}

const int maxn = 2e5 + 10;

struct Node
{
	int x, y;
	Node() {}
	Node(int x, int y) : x(min(x, y)), y(max(x, y)) {}
	bool operator < (const Node &a) const { return x < a.x; }
} a[maxn];

int main()
{
	int n = Getint();
	for (int i = 0; i < n; ++ i)
		a[i] = Node(Getint(), Getint());
	if (n == 1)
	{
		puts("0");
		return 0;
	}
	sort(a, a + n);
	int Mx = 0, posMx;
	for (int i = 0; i < n; ++ i)
		if (a[i].y >= Mx)
		{
			Mx = a[i].y;
			posMx = i;
		}
	int Rmax = Mx, Rmin = a[0].y, Bmax = a[posMx].x, Bmin = a[0].x;
	for (int i = 1; i < n; ++ i)
	{
		if (i == posMx) continue;
		Chkmin(Rmin, a[i].y);
		Chkmax(Bmax, a[i].x);
	}
	LL ans = 1ll * (Rmax - Rmin) * (Bmax - Bmin);
	if (!posMx)
	{
		printf("%lld\n", ans);
		return 0;
	}
	Rmax = Mx, Rmin = a[0].x, Bmax = max(max(a[0].y, a[posMx].x), a[n - 1].x), Bmin = min(min(a[0].y, a[posMx].x), a[1].x);
	Chkmin(ans, 1ll * (Rmax - Rmin) * (Bmax - Bmin));
	int preMn = a[0].y;
	a[n].y = Mx;
	for (int i = 1; i < n; ++ i)
	{
		if (i == posMx)
		{
			Chkmin(preMn, a[i].x);
			continue;
		}
		Chkmin(preMn, a[i].y);
		Chkmax(Bmax, a[i].y);
		Bmin = min(preMn, a[i + 1].x);
		Chkmin(ans, 1ll * (Rmax - Rmin) * (Bmax - Bmin));
	}
	printf("%lld\n", ans);
	return 0;
}

Submission Info

Submission Time
Task E - Ball Coloring
User survivor
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1925 Byte
Status AC
Exec Time 29 ms
Memory 1792 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 28 ms 1792 KB
div21 AC 28 ms 1792 KB
div22 AC 29 ms 1792 KB
div23 AC 29 ms 1792 KB
div24 AC 29 ms 1792 KB
example0 AC 0 ms 128 KB
example1 AC 0 ms 128 KB
example2 AC 0 ms 128 KB
maxrand0 AC 29 ms 1792 KB
maxrand1 AC 29 ms 1792 KB
maxrand2 AC 29 ms 1792 KB
maxrand20 AC 21 ms 1792 KB
maxrand21 AC 25 ms 1792 KB
maxrand210 AC 20 ms 1792 KB
maxrand211 AC 23 ms 1792 KB
maxrand22 AC 23 ms 1792 KB
maxrand23 AC 25 ms 1792 KB
maxrand24 AC 28 ms 1792 KB
maxrand25 AC 22 ms 1792 KB
maxrand26 AC 22 ms 1792 KB
maxrand27 AC 25 ms 1792 KB
maxrand28 AC 27 ms 1792 KB
maxrand29 AC 29 ms 1792 KB
maxrand3 AC 29 ms 1792 KB
maxrand4 AC 29 ms 1792 KB
smallrand0 AC 0 ms 128 KB
smallrand1 AC 0 ms 128 KB
smallrand2 AC 0 ms 128 KB
smallrand3 AC 0 ms 128 KB
smallrand4 AC 0 ms 128 KB
sparse0 AC 23 ms 1792 KB
sparse1 AC 22 ms 1792 KB
sparse2 AC 23 ms 1792 KB
sparse3 AC 22 ms 1792 KB
sparse4 AC 22 ms 1792 KB