# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
731562 | danikoynov | Aliens (IOI16_aliens) | C++14 | 1 ms | 1876 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 "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
struct interval
{
ll left, right;
interval(ll _left = 0, ll _right = 0)
{
left = _left;
right = _right;
}
};
bool cmp(const interval &it1, const interval &it2)
{
if (it1.left == it2.left)
return it1.right > it2.right;
return it1.left < it2.left;
}
const ll inf = 1e18;
interval h[maxn];
ll dp[1010][1010];
ll area(ll left, ll right)
{
if (left > right)
return 0;
return (right - left + 1) * (right - left + 1);
}
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c)
{
vector < interval > vec;
for (int i = 0; i < n; i ++)
{
if (r[i] > c[i])
swap(r[i], c[i]);
interval cur(r[i], c[i]);
vec.push_back(cur);
}
sort(vec.begin(), vec.end(), cmp);
n = 0;
int to = -1;
for (int i = 0; i < vec.size(); i ++)
{
if (vec[i].right > to)
{
to = vec[i].right;
h[++ n] = vec[i];
}
}
///for (int i = 1; i <= n; i ++)
/// cout << h[i].left << " : " << h[i].right << endl;
for (int i = 0; i <= n; i ++)
for (int j = 0; j <= k; j ++)
dp[i][j] = inf;
dp[0][0] = 0;
h[0] = interval(-1, -1);
for (int i = 1; i <= n; i ++)
{
for (int j = 1; j <= k; j ++)
{
for (int p = 1; p <= i; p ++)
{
dp[i][j] = min(dp[i][j], dp[p - 1][j - 1] + area(h[p].left, h[p].right) - area(h[p].left, h[p - 1].right));
}
}
}
/**for (int i = 1; i <= n; i ++, cout << endl)
for (int j = 1; j <= k; j ++)
cout << dp[i][j] << " ";*/
return dp[n][k];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |