# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105114 | fbosnjak | Cover (COCI18_cover) | C++14 | 93 ms | 760 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>
using namespace std;
#define ll long long
const int maxn = 5050;
const ll maxv = 1e12;
int N;
ll a, b;
vector <pair <ll, ll> > v, v1;
ll dp[maxn];
vector <pair <ll, ll> > convex;
int ccw(pair <ll, ll> x, pair <ll, ll> y, pair <ll, ll> z)
{
ll val = x.first * (y.second - z.second) +
y.first * (z.second - x.second) +
z.first * (x.second - y.second);
if (val > 0) return 1;
if (val == 0) return 0;
if (val < 0) return -1;
}
ll bs(ll x)
{
ll curr = maxv;
int lou = 0, haj = convex.size() - 1, mid;
while (haj - lou > 2)
{
mid = (lou + haj) / 2;
ll _mid = x * convex[mid].first + convex[mid].second;
ll _donji = x * convex[mid - 1].first + convex[mid - 1].second;
ll _veci = x * convex[mid + 1].first + convex[mid + 1].second;
bool koji = 0;
if (_donji > _veci) koji = 1;
if (!koji)
{
if (_donji > _mid) return _mid;
haj = mid;
}
else
{
if (_veci > _mid) return _mid;
lou = mid;
}
}
ll mini = maxv;
for (int i = lou; i <= haj; i++) mini = min(mini, x * convex[i].first + convex[i].second);
return mini;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N;
for (int i = 0; i < N; i++)
{
cin >> a >> b;
a = abs(a);
b = abs(b);
v1.push_back(make_pair(a, b));
}
for (int i = 0; i < v1.size(); i++)
{
bool da = 1;
for (int j = 0; j < v1.size(); j++)
{
if (v1[i].first < v1[j].first && v1[i].second <= v1[j].second) da = 0;
if (v1[i].first <= v1[j].first && v1[i].second < v1[j].second) da = 0;
}
if (da) v.push_back(v1[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
convex.push_back(make_pair(v[0].second, 0));
for (int i = 0; i < v.size(); i++)
{
dp[i] = bs(v[i].first);
if (i < v.size() - 1)
{
while (convex.size() >= 2 && ccw(convex[convex.size() - 2], convex[convex.size() - 1], make_pair(v[i + 1].second, dp[i])) != -1) convex.pop_back();
convex.push_back(make_pair(v[i + 1].second, dp[i]));
}
}
cout << dp[v.size() - 1] * 4;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |