Submission #144409

# Submission time Handle Problem Language Result Execution time Memory
144409 2019-08-16T20:24:14 Z vladciuperceanu Cover (COCI18_cover) C++14
120 / 120
16 ms 2040 KB
#include <iostream>
#include <set>
#define xx first
#define yy second

using namespace std;

int n,i,j,x,y;
long long d[20005];
pair<long long, long long> v[20005],drept[20005];
set< pair<long long, long long> > s;

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));
    }
    int m = 0;
    for (set< pair<long long, long long> >::iterator it=s.begin(); it!=s.end(); it++)
        v[++m] = make_pair(it->first, it->second);
    long long minim = v[1].yy; long long maxim = v[1].yy; int k = 0;
    for (i=2; i<=m; i++)
    {
        if (v[i].xx >= 0)
            break;
        if (v[i].xx == v[i-1].xx)
        {
            maxim = max(maxim, v[i].yy);
            minim = min(minim, v[i-1].yy);
        }
        else
        {
            if (maxim-minim > drept[k].yy || k == 0)
                drept[++k] = make_pair(-v[i-1].xx*2, maxim-minim);
            maxim = v[i].yy; minim = v[i].yy;
        }
    }
    if (maxim-minim > drept[k].yy || k == 0)
        drept[++k] = make_pair(-v[i-1].xx*2, maxim-minim);
    for (i=1; i<=k; i++)
    {
        d[i] = drept[1].xx*drept[i].yy;
        for (j=i; j>=1; j--)
            d[i] = min(d[i], d[j-1]+drept[i].yy*drept[j].xx);
    }
    cout << d[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 376 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 508 KB Output is correct
8 Correct 5 ms 632 KB Output is correct
9 Correct 11 ms 1400 KB Output is correct
10 Correct 16 ms 2040 KB Output is correct