이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*input
*/
#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
}
using namespace my_template;
const int MOD = 1000000007;
const ll INF = 1e17;
const int MX = 100101;
int N, M, K;
vpl sk;
// y < x
void sanitize(vi &r, vi &c) {
vpi temp;
for (int i = 0; i < N; ++i)
{
if (r[i] > c[i]) swap(r[i], c[i]);
temp.emplace_back(c[i], r[i]);
}
sort(temp.begin(), temp.end(), [](const pi & a, const pi & b) {
return a.x < b.x or (a.x == b.x and a.y > b.y);
});
for (int i = 0; i < N; ++i)
{
while (sk.size() and (int)sk.back().y >= temp[i].y) sk.pop_back();
sk.push_back(temp[i]);
}
N = (int)sk.size();
sk.insert(sk.begin(), { -1, -1});
// for (auto u : sk) printf("%d %d\n", u.x, u.y);
}
ll take_photos(int n, int m, int k, vi r, vi c) {
N = n; M = m; K = k;
sanitize(r, c);
vll dp(K + 1, vl(N + 1, INF));
dp[0][0] = 0;
for (k = 1; k <= K; ++k)
{
for (n = 1; n <= N; ++n)
{
dp[k][n] = dp[k - 1][n];
for (int t = 0; t < n; ++t)
{
ll newVal = dp[k - 1][t] + (sk[n].x - sk[t + 1].y + 1) * (sk[n].x - sk[t + 1].y + 1)
- max(sk[t].x - sk[t + 1].y + 1, 0ll) * max(sk[t].x - sk[t + 1].y + 1, 0ll);
if (newVal < dp[k][n]) {
dp[k][n] = newVal;
}
}
}
}
return dp[K][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... |