이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN=1e5+10;
const long long INF=1e16;
struct Interval {
int l;
int r;
bool friend operator < (Interval a, Interval b) {
if (a.l==b.l) return a.r>b.r;
return a.l<b.l;
}
};
Interval b[MAXN];
vector <Interval> a;
vector <long long> dp[MAXN];
long long take_photos(int n, int m, int k, vector <int> r, vector <int> c) {
for (int i=0;i<n;i++) {
b[i].l=min(r[i],c[i]);
b[i].r=max(r[i],c[i]);
}
sort(b,b+n);
int maxr=b[0].r;
a.push_back({0,0});
a.push_back(b[0]);
for (int i=1;i<n;i++) {
if (b[i].r<=maxr) continue;
a.push_back(b[i]);
maxr=max(maxr,b[i].r);
}
n=a.size()-1;
k=min(n,k);
for (int i=0;i<=n;i++) dp[i].resize(k+1);
long long dif;
dp[0][0]=0;
for (int i=1;i<=n;i++) {
dp[i][0]=INF;
for (int j=1;j<=k;j++) {
dp[i][j]=dp[i][j-1];
if (i<j) continue;
for (int p=i;p>=j;p--) {
if (j==1 && p!=1) continue;
dif=a[i].r-a[p].l+1;
dp[i][j]=min(dp[i][j],dp[p-1][j-1]+dif*dif);
}
}
}
return dp[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... |