이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
// #define int long longa
vector<pair<int, int>> intervals;
long long cost(int i, int l) {
long long overlap = max(0, intervals[l].second-intervals[l+1].first+1);
return (long long)(intervals[i].second-intervals[l+1].first+1)*(long long)(intervals[i].second-intervals[l+1].first+1) - overlap*overlap;
}
long long take_photos(signed n, signed m, signed k, vector<signed> r, vector<signed> c) {
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);
vector<vector<long long>> dp(k+1, vector<long long>(n+1, 1ll<<60));
dp[0][0] = 0;
for(int j = 1; j <= k; j++) {
for(int i = j; i <= n; i++) {
for(int l = 0; l < i; l++) {
dp[j][i] = min(dp[j][i], dp[j-1][l] + cost(i, l));
}
}
}
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... |