이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
#define ll long long
#define INF numeric_limits<ll>::max()/2
#define pll pair<ll, ll>
using namespace std;
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c)
{
vector<pll> a(n);
for(ll i = 0; i < n; i++)
{
a[i] = {r[i], c[i]};
if(c[i] < r[i]) //Mirror to diagonal or above
{
swap(a[i].first, a[i].second);
}
}
sort(a.begin(), a.end());
vector<pll> b(0);
for(ll i = 0; i < n; i++)
{
if((i == n-1 || a[i].first != a[i+1].first) && (b.empty() || a[i].second > b.back().second))
{
b.push_back(a[i]);
}
}
a = b;
n = a.size();
vector<vector<ll>> dp(n+1, vector<ll> (k+1, INF));
dp[0][0] = 0;
for(ll i = 1; i <= n; i++)
{
for(ll j = 1; j <= k; j++)
{
dp[i][j] = dp[i][j-1];
for(ll b = 1; b <= i; b++)
{
ll val = dp[b-1][j-1];
ll root = max(a[i-1].second-a[i-1].first+1, a[b-1].second-a[b-1].first+1);
ll area = root*root; //Area of the necessary square to cover the given cells
if(b > 1 && a[b-1].first <= a[b-2].second)
{
//Calculate the overlap with the previous square
root = a[b-2].second-a[b-1].first+1;
area -= root*root;
}
val += area;
dp[i][j] = min(dp[i][j], val);
}
}
}
return dp[n][k];
}
# | 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... |