이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
typedef long long ll;
ll take_photos(int N, int M, int K, std::vector<int> r, std::vector<int> c)
{
vector<pair<ll, ll>> v(N);
for (int i = 0; i < N; i++)
{
int Y = r[i], X = c[i];
if (X > Y) swap(X, Y);
v[i] = make_pair(X, Y);
}
sort(v.begin(), v.end(), [&](const pair<int, int> &a, const pair<int, int> &b) {return (a.first == b.first ? a.second < b.second : a.first > b.first);});
vector<pair<ll, ll>> pareto;
for (auto [X, Y] : v)
{
while (!pareto.empty() && pareto.back().second <= Y) pareto.pop_back();
pareto.emplace_back(X, Y);
}
v = pareto;
reverse(v.begin(), v.end()); //So pra ficar ordenado por X
N = v.size(); v.insert(v.begin(), make_pair(-1, -1));
vector<ll> sIni(N+1), inter(N+1);
for (int i = 1; i < N; i++) inter[i] = (v[i+1].first > v[i].second ? 0 : (v[i].second - v[i+1].first + 1)*(v[i].second - v[i+1].first + 1));
for (int i = 1; i <= N; i++) sIni[i] = (v[i].second - v[i].first + 1)*(v[i].second - v[i].first + 1) + sIni[i-1] - inter[i-1];
//Ate aqui estou so reduzindo o problema
auto C = [&](int l, int r) {return (v[r].second - v[l].first + 1) * (v[r].second - v[l].first + 1) - (sIni[r] - sIni[l-1] + inter[l-1]);};
vector<vector<ll>> dp(N+1, vector<ll>(K+1));
for (int k = 1; k <= K; k++)
{
for (int i = 1; i <= N; i++)
{
if (i <= k) {dp[i][k] = 0; continue;}
dp[i][k] = 0x3f3f3f3f3f3f3f3f;
for (int j = 1; j <= i; j++)
dp[i][k] = min(dp[i][k], dp[j-1][k-1] + C(j, i));
}
}
return dp[N][K] + sIni[N];
}
# | 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... |