이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> p;
int L[100005], R[100005];
long long dp[40005][5005];
void run(int l, int r, int opt_l, int opt_r, int lv){
if(l > r) return;
int mid = (l+r)>>1;
int new_opt = -1;
for(int x=opt_l; x<=min(opt_r, mid); x++){
long long cst = dp[x-1][lv-1]+1LL*(R[mid]-L[x]+1)*(R[mid]-L[x]+1)-(R[x-1]-L[x]+1 > 0 ? 1LL*(R[x-1]-L[x]+1)*(R[x-1]-L[x]+1): 0LL);
if(cst < dp[mid][lv]){
dp[mid][lv] = cst;
new_opt = x;
}
}
run(l, mid-1, opt_l, new_opt, lv);
run(mid+1, r, new_opt, opt_r, lv);
return;
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){
for(int i=0; i<n; i++) p.push_back({min(r[i], c[i]), -max(r[i], c[i])});
sort(p.begin(), p.end());
int N=1, tmp_mx=-1;
for(int i=0; i<n; i++){
if(-p[i].second > tmp_mx){
L[N] = p[i].first, R[N] = -p[i].second;
tmp_mx = -p[i].second;
N++;
}
}
N--;
R[0] = -1e9;
for(int i=0; i<=N; i++) for(int j=0; j<=k; j++) dp[i][j] = 1e18;
dp[0][0] = 0;
for(int i=1; i<=N; i++) dp[i][1] = 1LL*(R[i]-L[1]+1)*(R[i]-L[1]+1);
for(int i=2; i<=k; i++) run(1, N, 1, N, i);
return dp[N][min(N, k)];
}
# | 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... |