Submission #2235085


Source Code Expand

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

constexpr int MAXN = 2e5 + 10;

int n;
long long x[MAXN], y[MAXN];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld%lld", x + i, y + i);
		if (x[i] < y[i]) swap(x[i], y[i]);
	}
	x[0] = LLONG_MIN;
	y[0] = LLONG_MAX;
	int max_pos = 0, min_pos = 0;
	for (int i = 1; i <= n; ++i) {
		if (x[max_pos] < x[i]) max_pos = i;
		if (y[min_pos] > y[i]) min_pos = i;
		if (y[min_pos] == y[i] && min_pos == max_pos)
			min_pos = i;
	}
	long long ans = LLONG_MAX;
	{ // case 1 : rmax == max, bmin == min
		long long rmax = x[max_pos], rmin = LLONG_MAX;
		long long bmin = y[min_pos], bmax = LLONG_MIN;
		for (int i = 1; i <= n; ++i) {
			rmin = min(rmin, x[i]);
			bmax = max(bmax, y[i]);
		}
		ans = min(ans, (rmax - rmin) * (bmax - bmin));
	}
	
	if (max_pos != min_pos) { // case2 : rmax == max, rmin == min
		long long rdiff = x[max_pos] - y[min_pos];
		set<pair<long long, long long> > sets;
		for (int i = 1; i <= n; ++i)
			sets.insert(make_pair(x[i], i));
		for (;;) {
			long long bdiff = sets.rbegin()->first - sets.begin()->first;
			ans = min(ans, rdiff * bdiff);
			pair<long long, long long> temp = *sets.rbegin();
			sets.erase(*sets.rbegin());
			if (temp.second == -1) break;
			sets.insert(make_pair(y[temp.second], -1));
		}
	}
	printf("%lld\n", ans);
}

Submission Info

Submission Time
Task E - Ball Coloring
User UglyAndPretty
Language C++14 (GCC 5.4.1)
Score 700
Code Size 1381 Byte
Status AC
Exec Time 202 ms
Memory 15872 KB

Compile Error

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

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 121 ms 15872 KB
div21 AC 121 ms 15872 KB
div22 AC 122 ms 15872 KB
div23 AC 123 ms 15872 KB
div24 AC 121 ms 15872 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 122 ms 15872 KB
maxrand1 AC 121 ms 15872 KB
maxrand2 AC 123 ms 15872 KB
maxrand20 AC 161 ms 15872 KB
maxrand21 AC 176 ms 15872 KB
maxrand210 AC 153 ms 15872 KB
maxrand211 AC 172 ms 15872 KB
maxrand22 AC 185 ms 15872 KB
maxrand23 AC 195 ms 15872 KB
maxrand24 AC 191 ms 15872 KB
maxrand25 AC 155 ms 15872 KB
maxrand26 AC 158 ms 15872 KB
maxrand27 AC 194 ms 15872 KB
maxrand28 AC 186 ms 15872 KB
maxrand29 AC 202 ms 15872 KB
maxrand3 AC 122 ms 15872 KB
maxrand4 AC 122 ms 15872 KB
smallrand0 AC 1 ms 256 KB
smallrand1 AC 1 ms 256 KB
smallrand2 AC 1 ms 256 KB
smallrand3 AC 1 ms 256 KB
smallrand4 AC 1 ms 256 KB
sparse0 AC 109 ms 15872 KB
sparse1 AC 107 ms 15872 KB
sparse2 AC 114 ms 15872 KB
sparse3 AC 113 ms 15872 KB
sparse4 AC 111 ms 15872 KB