이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<pair<int, int>> intervals;
int cost(int i, int l) {
int overlap = max(0ll, intervals[l].second-intervals[l+1].first+1);
return (intervals[i].second-intervals[l+1].first+1)*(intervals[i].second-intervals[l+1].first+1) - overlap*overlap;
}
signed n;
vector<vector<int>> dp, opt;
int j;
void recurse(int l, int r) {
if(l==r) return;
int i = (l+r)/2;
for(int cur = opt[j][l-1]; cur < (r==n+1?i:opt[j][r]+1); cur++) {
if(dp[j-1][cur] + cost(i, cur) < dp[j][i]) {
opt[j][i] = cur;
dp[j][i] = dp[j-1][cur] + cost(i, cur);
}
}
if(l+1 != r) {
recurse(l, i);
recurse(i+1, r);
}
}
long long take_photos(signed N, signed m, signed k, vector<signed> r, vector<signed> c) {
n=N;
for(int i = 0; i < n; i++) {
if(c[i] >= r[i])
intervals.push_back({r[i], -c[i]});
else
intervals.push_back({c[i], -r[i]});
}
sort(intervals.begin(), intervals.end());
auto interStore = intervals;
intervals.clear();
intervals.push_back({-1, -1});
int ma = -1;
for(auto p: interStore) {
if(-p.second > ma) {
ma = -p.second;
intervals.push_back({p.first, -p.second});
}
}
n = intervals.size()-1;
k = min(k, n);
dp.assign(k+1, vector<int>(n+1, 1ll<<60));
opt.assign(k+1, vector<int>(n+1, 0));
dp[0][0] = 0;
// queue<pair<int, int>> ranges;
for(j = 1; j <= k; j++) {
recurse(1ll, (int)n+1);
}
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... |