Submission #141680

# Submission time Handle Problem Language Result Execution time Memory
141680 2019-08-08T20:48:29 Z mariusnicoli Cover (COCI18_cover) C++14
96 / 120
16 ms 1912 KB
#include <iostream>
#include <set>

using namespace std;
struct elem {
    long long x;
    long long y;
};

struct dreptunghi {
    long long dimx;
    long long dimy;
};

set<pair<long long, long long> > s;
elem v[20010];
dreptunghi d[20010];
long long dp[20010];
long long n, k, i, x, y, minim, maxim, sol;
long long sp[20010], SP[20010];

int main () {

    cin>>n;
    for (i=1;i<=n;i++) {
        cin>>x>>y;
        s.insert(make_pair(x, y));
        s.insert(make_pair(-x, y));
        s.insert(make_pair(x, -y));
        s.insert(make_pair(-x, -y));
    }

    n = 0;
    for (set<pair<long long, long long> >::iterator it = s.begin(); it!=s.end(); it++) {
        v[++n].x = it->first;
        v[n].y = it->second;
    }

    minim = v[1].y;
    maxim = v[1].y;
    for (i=2;i<=n;i++) {
        if (v[i].x >= 0)
            break;
        if (v[i].x == v[i-1].x) {
            maxim = max(maxim, v[i].y);
            minim = min(minim, v[i].y);
        } else {
            if (k == 0 || maxim-minim > d[k].dimy) {
                d[++k].dimx = -v[i-1].x*2;
                d[k].dimy = maxim - minim;
                maxim = v[i].y;
                minim = v[i].y;
            }
        }
    }
    if (k == 0 || maxim-minim > d[k].dimy) {
        d[++k].dimx = -v[i-1].x * 2;
        d[k].dimy = maxim - minim;
    }

    for (i=1;i<=k;i++) {
        dp[i] = d[1].dimx*d[i].dimy;
        for (long long j=i;j>=2;j--) {
            dp[i] = min(dp[i], dp[j-1] + d[j].dimx * d[i].dimy);
        }
    }
    cout<<dp[k];

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 4 ms 760 KB Output is correct
9 Incorrect 10 ms 1272 KB Output isn't correct
10 Incorrect 16 ms 1912 KB Output isn't correct