# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
530731 | Killer2501 | Cover (COCI18_cover) | C++14 | 3 ms | 864 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 ll long long
#define ld long double
#define ull unsigned long long
#define pb push_back
#define pll pair<ll, ll>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 5e3+5;
const int M = 250;
const int mod = 1e9+7;
const ll base = 75;
const int inf = 1e9;
int n, t, b[N][N], d[N], lab[N], c[N], a[N][N];
ll ans, tong, dp[N];
ll m, k;
pii p[N], start, finish;
vector<int> gx[N], gy[N];
vector<pii> vi;
string s[N];
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> p[i].fi >> p[i].se;
p[i].fi = abs(p[i].fi);
p[i].se = abs(p[i].se);
}
sort(p+1, p+1+n);
for(int i = 1; i <= n; i ++)
{
while(!vi.empty() && vi.back().se <= p[i].se)vi.pop_back();
vi.pb(p[i]);
}
for(int i = 1; i <= vi.size(); i ++)
{
dp[i] = 1ll * vi[0].se * vi[i-1].fi;
for(int j = 1; j <= i; j ++)
{
dp[i] = min(dp[i], dp[j-1] + 1ll*vi[j-1].se * vi[i-1].fi);
}
}
cout << dp[vi.size()]*4;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |