Submission #1696080


Source Code Expand

#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n; 
    using XY = tuple<ll, ll>;
    vector<XY> in(n);
    ll minv = inf, maxv = 0;
    rep(i, n){
        ll x, y; cin >> x >> y;
        if(x > y) swap(x, y);
        in[i] = XY(x, y);
        chmin(minv, x);
        chmax(maxv, y);
    }
    sort(_all(in));

    ll res = 0;
    {
        ll maxr = minv, minb = maxv;
        rep(i, n){
            ll x, y; tie(x, y) = in[i];
            chmax(maxr, x);
            chmin(minb, y);
        }
        res = (maxr - minv) * (maxv - minb);
    }

    using Elem = tuple<ll, int, bool>;
    priority_queue<Elem, vector<Elem>, greater<Elem>> q;
    ll l = minv, r = minv;
    rep(i, n){
        ll x, y; tie(x, y) = in[i];
        q.push(Elem(x, i, false));
        chmax(r, x);
    }

    chmin(res, (maxv - minv) * (r - l));
    while(true){
        Elem cur = q.top(); q.pop();
        ll v; int idx; bool used; tie(v, idx, used) = cur;
        if(used) break;
        ll nv; tie(ignore, nv) = in[idx];
        q.push(Elem(nv, idx, true));
        chmax(r, nv);
        l = get<0>(q.top());
        chmin(res, (maxv - minv) * (r - l));
    }

    cout << res << endl;

    return 0;
}

Submission Info

Submission Time
Task E - Ball Coloring
User nokoTaro
Language C++14 (GCC 5.4.1)
Score 700
Code Size 3033 Byte
Status AC
Exec Time 67 ms
Memory 9712 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 60 ms 8048 KB
div21 AC 62 ms 9200 KB
div22 AC 61 ms 9712 KB
div23 AC 60 ms 7664 KB
div24 AC 61 ms 8560 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 60 ms 7792 KB
maxrand1 AC 61 ms 9328 KB
maxrand2 AC 60 ms 8048 KB
maxrand20 AC 65 ms 8688 KB
maxrand21 AC 66 ms 8944 KB
maxrand210 AC 64 ms 9328 KB
maxrand211 AC 65 ms 8432 KB
maxrand22 AC 64 ms 7792 KB
maxrand23 AC 65 ms 7920 KB
maxrand24 AC 66 ms 8176 KB
maxrand25 AC 67 ms 9456 KB
maxrand26 AC 66 ms 9328 KB
maxrand27 AC 66 ms 9584 KB
maxrand28 AC 65 ms 7664 KB
maxrand29 AC 66 ms 9072 KB
maxrand3 AC 60 ms 8688 KB
maxrand4 AC 61 ms 8688 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 61 ms 8048 KB
sparse1 AC 62 ms 9200 KB
sparse2 AC 60 ms 8176 KB
sparse3 AC 61 ms 9584 KB
sparse4 AC 61 ms 9584 KB