Submission #2245760


Source Code Expand

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=200005;
struct node { int x,y; } a[N];
LL an;
int z[N],s[N],i,j,k,n,m,x,y,l1,l2,r1,r2,l,r,L,R;
bool P;
char c;

inline char getc()
{
	#define VV 10000000
	static char s[VV],*l=s,*r=s;
	if (l==r)
		l=s,r=s+fread(s,1,VV,stdin);
	return l==r?0:*l++;
}

int read(){ int z=0; do c=getc(); while (c<'0'||c>'9'); while (c>='0'&&c<='9') z*=10,z+=c-'0',c=getc(); return z; }

bool cmp(node a,node b){ return a.x<b.x; }

void solve()
{
	sort(a+1,a+n+1,cmp);
	int D=1e9;
	for (i=1;i<=n;++i)
		an=min(an,(LL)(R-L)*(r1-min(a[i].x,D))),
		D=min(D,a[i].y),
		r1=max(r1,a[i].y);
}

int main()
{
	n=read(),L=1e9;
	for (i=1;i<=n;++i)
	{
		a[i]=(node){read(),read()};
		if (a[i].x>a[i].y) swap(a[i].x,a[i].y);
		L=min(L,a[i].x),R=max(R,a[i].y);
	}
	if (n==1||L==R)
	{
		puts("0");
		return 0;
	}
	l1=l2=1e9;
	for (i=1;i<=n;++i)
		x=a[i].x,y=a[i].y,
		l1=min(l1,x),r1=max(r1,x),
		l2=min(l2,y),r2=max(r2,y);
	an=(LL)(r1-l1)*(r2-l2);
	solve();
	printf("%lld\n",an);
	return 0;
}

Submission Info

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