# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
239012 | VEGAnn | Cover (COCI18_cover) | C++14 | 7 ms | 512 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define i2 array<int,2>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 5010;
const ll OO = 1e18;
vector<i2> vc;
i2 a[N];
int x[N], y[N], n;
ll f[N];
void upd(ll &x, ll y){
x = min(x, y);
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i][0] >> a[i][1];
a[i][0] = abs(a[i][0]);
a[i][1] = abs(a[i][1]);
}
sort(a, a + n);
reverse(a, a + n);
vc.PB(a[0]);
for (int i = 1; i < n; i++)
if (a[i][1] > vc.back()[1])
vc.PB(a[i]);
reverse(all(vc));
f[0] = 0;
n = sz(vc);
fill(f + 1, f + n + 1, OO);
for (int i = 0; i < n; i++)
for (int j = i + 1; j <= n; j++)
upd(f[j], f[i] + ll(vc[i][1]) * ll(vc[j - 1][0]));
cout << f[n] * 4;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |