Submission #8523533


Source Code Expand

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
const ll INF = 1e9;

const int MAXN = 2.1e5;
int N;
int X[MAXN];
int Y[MAXN];
pair<int, int> P[MAXN];
int minx[MAXN];
int maxx[MAXN];
int miny[MAXN];
int maxy[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i];
		if (X[i] > Y[i]) swap(X[i], Y[i]);
		P[i] = {X[i], Y[i]};
	}
	sort(P, P + N);
	for (int i = 0; i < N; i++) {
		tie(X[i],Y[i]) = P[i];
	}

	ll ans = ll(*max_element(X,X+N) - *min_element(X,X+N)) * ll(*max_element(Y,Y+N) - *min_element(Y,Y+N));
	int V = *max_element(Y,Y+N) - *min_element(X,X+N);
	miny[0] = INF;
	maxy[0] = -INF;
	for (int i = 0; i < N; i++) {
		miny[i+1] = min(miny[i], Y[i]);
		maxy[i+1] = max(maxy[i], Y[i]);
	}
	minx[N] = INF;
	maxx[N] = -INF;
	for (int i = N-1; i >= 0; i--) {
		minx[i] = min(minx[i+1], X[i]);
		maxx[i] = max(maxx[i+1], X[i]);
	}
	for (int i = 0; i <= N; i++) {
		ans = min(ans, ll(V)*ll(max(maxx[i],maxy[i]) - min(minx[i],miny[i])));
	}

	cout << ans << '\n';

	return 0;
}

Submission Info

Submission Time
Task E - Ball Coloring
User ecnerwala
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1135 Byte
Status AC
Exec Time 63 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 59 ms 6784 KB
div21 AC 59 ms 6656 KB
div22 AC 59 ms 6656 KB
div23 AC 59 ms 6784 KB
div24 AC 59 ms 6784 KB
example0 AC 2 ms 4352 KB
example1 AC 2 ms 4352 KB
example2 AC 2 ms 4352 KB
maxrand0 AC 59 ms 6656 KB
maxrand1 AC 59 ms 6656 KB
maxrand2 AC 59 ms 6656 KB
maxrand20 AC 63 ms 6784 KB
maxrand21 AC 61 ms 6784 KB
maxrand210 AC 60 ms 6784 KB
maxrand211 AC 61 ms 6784 KB
maxrand22 AC 62 ms 6656 KB
maxrand23 AC 62 ms 6656 KB
maxrand24 AC 60 ms 6656 KB
maxrand25 AC 61 ms 6656 KB
maxrand26 AC 62 ms 6656 KB
maxrand27 AC 62 ms 6656 KB
maxrand28 AC 61 ms 6784 KB
maxrand29 AC 60 ms 6784 KB
maxrand3 AC 59 ms 6784 KB
maxrand4 AC 59 ms 6656 KB
smallrand0 AC 2 ms 4352 KB
smallrand1 AC 2 ms 4352 KB
smallrand2 AC 2 ms 4352 KB
smallrand3 AC 2 ms 4352 KB
smallrand4 AC 2 ms 4352 KB
sparse0 AC 60 ms 6784 KB
sparse1 AC 59 ms 6656 KB
sparse2 AC 59 ms 6784 KB
sparse3 AC 59 ms 6784 KB
sparse4 AC 61 ms 6656 KB