Submission #8530658
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<int, int> ii;
typedef long long ll;
const int len = 2e5+5, inf = 1e9+5;
int suf[2*len];
ii arr[len];
vector<ii> vec;
int main(){
int n, mn = inf, mx = -inf, mnrig = inf, mxlef = -inf;
scanf("%d", &n);
for (int i = 0; i < n; i++){
scanf("%d %d", &arr[i].fi, &arr[i].se);
if (arr[i].fi > arr[i].se)
swap(arr[i].fi, arr[i].se);
mn = min(mn, arr[i].fi);
mx = max(mx, arr[i].se);
mnrig = min(mnrig, arr[i].se);
mxlef = max(mxlef, arr[i].fi);
}
if (n == 1){
printf("0\n");
return 0;
}
for (int i = 0; i < n; i++){
vec.pb(mp(arr[i].fi, i));
vec.pb(mp(arr[i].se, -1));
}
sort(vec.begin(), vec.end());
suf[2*n-1] = -inf;
for (int i = 2*n-2; i >= 0; i--){
suf[i] = suf[i+1];
if (vec[i+1].se != -1)
suf[i] = max(suf[i], vec[i+1].fi);
}
ll ans = (mxlef-mn)*1LL*(mx-mnrig);
for (int i = 0, cur = -inf; i < 2*n; i++){
ans = min(ans, (mx-mn)*1LL*(max(cur, suf[i])-vec[i].fi));
//printf("i = %d, po = %d, tp = %d, cur = %d, suf = %d\n", i, vec[i].fi, vec[i].se, cur, suf[i]);
if (vec[i].se == -1)
break;
else
cur = max(cur, arr[vec[i].se].se);
}
printf("%lld\n", ans);
return 0;
}
Submission Info
Submission Time |
|
Task |
E - Ball Coloring |
User |
evpipis |
Language |
C++14 (GCC 5.4.1) |
Score |
700 |
Code Size |
1524 Byte |
Status |
AC |
Exec Time |
86 ms |
Memory |
7920 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:18:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &n);
^
./Main.cpp:20:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &arr[i].fi, &arr[i].se);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
700 / 700 |
Status |
|
|
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 |
82 ms |
6640 KB |
div21 |
AC |
83 ms |
7792 KB |
div22 |
AC |
82 ms |
7280 KB |
div23 |
AC |
82 ms |
7536 KB |
div24 |
AC |
82 ms |
6636 KB |
example0 |
AC |
1 ms |
256 KB |
example1 |
AC |
1 ms |
256 KB |
example2 |
AC |
1 ms |
256 KB |
maxrand0 |
AC |
82 ms |
6636 KB |
maxrand1 |
AC |
83 ms |
7408 KB |
maxrand2 |
AC |
82 ms |
7152 KB |
maxrand20 |
AC |
84 ms |
7792 KB |
maxrand21 |
AC |
83 ms |
7532 KB |
maxrand210 |
AC |
80 ms |
7152 KB |
maxrand211 |
AC |
85 ms |
6636 KB |
maxrand22 |
AC |
85 ms |
7280 KB |
maxrand23 |
AC |
85 ms |
6636 KB |
maxrand24 |
AC |
84 ms |
7408 KB |
maxrand25 |
AC |
83 ms |
6636 KB |
maxrand26 |
AC |
84 ms |
6636 KB |
maxrand27 |
AC |
85 ms |
7408 KB |
maxrand28 |
AC |
85 ms |
6896 KB |
maxrand29 |
AC |
84 ms |
7920 KB |
maxrand3 |
AC |
86 ms |
7024 KB |
maxrand4 |
AC |
82 ms |
6636 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 |
81 ms |
7280 KB |
sparse1 |
AC |
80 ms |
7792 KB |
sparse2 |
AC |
81 ms |
7408 KB |
sparse3 |
AC |
81 ms |
6636 KB |
sparse4 |
AC |
81 ms |
6768 KB |