Submission #1533186


Source Code Expand

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

vector<P> d;

//RMQ
struct SegTree {
    int N;
    vector<int> dat;
    SegTree() {}
    SegTree(int n) {
        N = 1;
        while(N < n) N *= 2;
        dat.resize(2 * N, INF);
        // for(int i = 0; i < 2*N-1; i++)
        //     dat[i] = INF;
    }
    // update k th element
    void update(int k, int a) {
        k += N-1; // leaf
        dat[k] = a; 
        while(k > 0) {
            k = (k - 1) / 2;
            dat[k] = min(dat[k*2+1], dat[k*2+2]);
        }
    }
    // min [a, b)
    int query(int a, int b) { return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        if(r <= a or b <= l) return INF;
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        return min(query(a, b, k*2+1, l, m), query(a, b, k*2+2, m, r));
    }
};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i];
        if(x[i] > y[i]) swap(x[i], y[i]);
        d. push_back(P(x[i], y[i]));
    }
    SegTree r(n), r2(n);
    sort(all(d));
    rep(i, 0, n){
        r.update(i, -d[i].second);
        r2.update(i, d[i].second);
    }
    int rMIN = 1e12, rMAX = 0, bMIN = 1e12, bMAX = 0;
    rep(i, 0, n){
        chmax(rMAX, x[i]);
        chmin(rMIN, x[i]);
        chmax(bMAX, y[i]);
        chmin(bMIN, y[i]);
    }
    int ans = (rMAX - rMIN) * (bMAX - bMIN);
    // cout << rMAX << " " << rMIN << " " << bMAX << " " << bMIN << endl;
    rep(i, 1, n){
        rMIN = d[i].first;
        rMAX = max(d[n - 1].first, -r.query(0, i));
        int cMIN = r2.query(0, i);
        if(cMIN < rMIN){
            chmax(rMAX, rMIN);            
            rMIN = cMIN;
        }
        bMIN = d[0].first;
        bMAX = -r.query(i, n);
        // cout << rMAX << " " << rMIN << " " << bMAX << " " << bMIN << endl;
        chmin(ans, (rMAX - rMIN) * (bMAX - bMIN));
    }
    cout << ans << endl; 
}

Submission Info

Submission Time
Task E - Ball Coloring
User treeone
Language C++14 (GCC 5.4.1)
Score 700
Code Size 2419 Byte
Status AC
Exec Time 151 ms
Memory 15852 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 149 ms 15212 KB
div21 AC 146 ms 14828 KB
div22 AC 146 ms 14828 KB
div23 AC 146 ms 14828 KB
div24 AC 146 ms 14828 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 146 ms 14828 KB
maxrand1 AC 146 ms 14828 KB
maxrand2 AC 148 ms 15084 KB
maxrand20 AC 149 ms 14828 KB
maxrand21 AC 149 ms 15724 KB
maxrand210 AC 149 ms 14828 KB
maxrand211 AC 151 ms 14828 KB
maxrand22 AC 149 ms 15212 KB
maxrand23 AC 149 ms 14828 KB
maxrand24 AC 148 ms 15084 KB
maxrand25 AC 149 ms 15468 KB
maxrand26 AC 149 ms 15596 KB
maxrand27 AC 149 ms 15468 KB
maxrand28 AC 151 ms 14828 KB
maxrand29 AC 147 ms 15596 KB
maxrand3 AC 146 ms 14828 KB
maxrand4 AC 147 ms 15084 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 147 ms 15852 KB
sparse1 AC 146 ms 14828 KB
sparse2 AC 146 ms 14956 KB
sparse3 AC 146 ms 14956 KB
sparse4 AC 147 ms 14828 KB