이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define pii pair<long long, long long>
#define st first
#define nd second
//#define endl "\n"
#define sp " "
#define N 4005
#define ll long long
vector<pii> o;
ll dp[N][N], M;
const ll INF = 2e18 + 7;
ll dist(int x, int y){
ll h = M - (x + y - 2);
h = max((ll)0, h);
return h * h;
}
ll cost(int i, int j){
if (i > j) swap(i, j);
pii x = o[i], y = o[j];
ll prv = 0;
if (i > 1) prv = dist(max(x.st, o[i - 1].st), max(x.nd, o[i - 1].nd));
ll curr = dist(min(x.st, y.st), min(x.nd, y.nd)) - prv;
return curr;
}
void f(int cnt, int l, int r, int sl, int sr){
if (l > r) return;
int mid = (l + r) / 2;
pii best = {INF, INF};
for (int i = sl; i <= min(sr, mid); i++){
best = min(best, {cost(i, mid) + dp[cnt - 1][i - 1], i});
}
ll opt = best.nd;
dp[cnt][mid] = best.st;
f(cnt, l, mid - 1, sl, opt);
f(cnt, mid + 1, r, opt, sr);
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pii> p;
M = m;
for (int i = 0; i < n; i++)
{
r[i]++, c[i]++;
int tmp = r[i];
r[i] = c[i];
c[i] = m - tmp + 1;
if (r[i] + c[i] > m + 1){
int tmp = r[i];
r[i] = m + 1 - c[i];
c[i] = m + 1 - tmp;
}
p.pb({r[i], c[i]});
}
sort(p.begin(), p.end());
pii last = {0, m + 5};
for (auto i : p){
if (i.nd < last.nd){
o.pb(i);
last = i;
}
}
o.pb({m + 1, 0});
reverse(o.begin(), o.end());
int gh = o.size();
ll ans = cost(1, 1);
for (int i = 2; i < gh; i++){
ans += cost(i, i);
}
return ans;
for (int i = 2; i <= k; i++)
{
f(i, 1, gh - 1, 1, gh - 1);
}
return dp[k][o.size() - 1];;
}
# | 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... |