Submission #1482509


Source Code Expand

#include<cstdio>
#include<cstring>
#include<algorithm>
#define x first
#define y second
using namespace std;
typedef long long LL;
 
const int maxn = 200009;
pair<int,int> a[maxn];
int n, tmp, _mx, _mn, mx, mn, best; 
LL ans = 1e18;
 
int main(){
	scanf("%d", &n);
	if (n == 1) { puts("0"); return 0; }
	a[0].x = 1e9 + 1;
	for (int i=1; i<=n; i++){
		scanf("%d%d", &a[i].x, &a[i].y);
		if (a[i].x > a[i].y) swap(a[i].x, a[i].y);
	}
	sort(a+1, a+n+1);
	for (int i=1; i<=n; i++)
		if (a[i].x <= a[_mn].x && a[i].y >= a[_mx].y) _mn = _mx = i;
		else if (a[i].x < a[_mn].x) _mn = i;
		else if (a[i].y > a[_mx].y) _mx = i;
	mn = 1e9 + 1;
	for (int i=1; i<=n; i++){
		mn = min(mn, a[i].y);
		mx = max(mx, a[i].x);
	}
	ans = 1LL * (mx-a[_mn].x) * (a[_mx].y-mn);
	//if (_mn != _mx){
		best = 1e9 + 1; mn = mx = a[1].y;
		for (int i=2; i<=n; i++){
			best = min(best, max(a[n].x, mx) - min(a[i].x, mn));
			mn = min(mn, a[i].y);
			mx = max(mx, a[i].y);
		}
		ans = min(ans, 1LL * best * (a[_mx].y - a[_mn].x));
	//}
	printf("%lld\n", ans);
	return 0;
}

Submission Info

Submission Time
Task E - Ball Coloring
User Cyanic
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1087 Byte
Status AC
Exec Time 60 ms
Memory 1664 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:15:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:19:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i].x, &a[i].y);
                                  ^

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 57 ms 1664 KB
div21 AC 57 ms 1664 KB
div22 AC 57 ms 1664 KB
div23 AC 57 ms 1664 KB
div24 AC 57 ms 1664 KB
example0 AC 1 ms 128 KB
example1 AC 0 ms 128 KB
example2 AC 0 ms 128 KB
maxrand0 AC 57 ms 1664 KB
maxrand1 AC 57 ms 1664 KB
maxrand2 AC 57 ms 1664 KB
maxrand20 AC 59 ms 1664 KB
maxrand21 AC 59 ms 1664 KB
maxrand210 AC 59 ms 1664 KB
maxrand211 AC 60 ms 1664 KB
maxrand22 AC 60 ms 1664 KB
maxrand23 AC 60 ms 1664 KB
maxrand24 AC 58 ms 1664 KB
maxrand25 AC 59 ms 1664 KB
maxrand26 AC 60 ms 1664 KB
maxrand27 AC 60 ms 1664 KB
maxrand28 AC 59 ms 1664 KB
maxrand29 AC 58 ms 1664 KB
maxrand3 AC 57 ms 1664 KB
maxrand4 AC 57 ms 1664 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 58 ms 1664 KB
sparse1 AC 57 ms 1664 KB
sparse2 AC 57 ms 1664 KB
sparse3 AC 57 ms 1664 KB
sparse4 AC 58 ms 1664 KB