이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<#x<<", "<<#y<<" = "<<x<<", "<<y<<"\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
const int inf=1000001000;
const int MAXN=100010, K=103;
int n, m, k;
pii A[MAXN];
ll dp[505][505];
inline ll _sq(ll x){ return x*x;}
ll take_photos(int _n, int _m, int _k, vector<int> r, vector<int> c) {
k=_k;
m=_m;
vector<pii> vec;
for (int i=0; i<_n; i++) vec.pb({min(r[i], c[i]), max(r[i], c[i])});
sort(all(vec), [](pii i, pii j){
if (i.second!=j.second) return i.second<j.second;
return i.first>j.first;
});
for (pii p:vec){
while (n && p.first<=A[n].first) n--;
A[++n]=p;
}
// for (int i=1; i<=n; i++) debugp(A[i])
k=min(k, n);
memset(dp, 63, sizeof(dp));
for (int i=0; i<=k; i++) dp[0][i]=0;
for (int i=1; i<=n; i++){
for (int j=1; j<=i; j++){
ll cost=_sq(A[i].second-A[j].first+1);
if (j!=1 && A[j].first<=A[j-1].second) cost-=_sq(A[j-1].second-A[j].first+1);
// cerr<<i<<" "<<j<<" "<<cost<<"\n";
for (int t=1; t<=k; t++)
dp[i][t]=min(dp[i][t], dp[j-1][t-1]+cost);
}
}
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... |