이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 5e4+10;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
ll ant[MAXN], dp[MAXN];
vector<pll> arr;
void dacCalc(int l, int r, int p, int q){
if(r<l) return;
int mid=(l+r)>>1;
int opt=-1;
ll val=LINF;
for(int i=p;i<=min(q, mid);i++){
ll curr=ant[i-1]+(arr[mid].se-arr[i].fi+1ll)*(arr[mid].se-arr[i].fi+1ll);
if(mid!=(int)arr.size()-1)
curr-=max(arr[mid].se-arr[mid+1].fi+1ll, 0ll)*(arr[mid].se-arr[mid+1].fi+1ll);
if(curr<val){
opt=i;
val=curr;
}
}
dp[mid]=val;
dacCalc(l, mid-1, p, opt);
dacCalc(mid+1, r, opt, q);
}
ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) {
vector<pll> proc;
for(int i=0;i<n;i++)
proc.pb({min(r[i], c[i]), max(r[i], c[i])});
sort(all(proc), [&](pll a, pll b){ return (a.fi!=b.fi ? a.fi<b.fi : a.se>b.se); });
arr.pb({-1, -1});
ll last=-1;
for(auto u : proc){
if(u.se<=last) continue;
arr.pb(u);
last=u.se;
}
int lim=(int)arr.size()-1;
for(int i=1;i<=lim;i++) dp[i]=1e13;
for(int i=0;i<k;i++){
for(int j=1;j<=lim;j++) ant[j]=dp[j];
dacCalc(1, lim, 1, lim);
}
return dp[(int)arr.size()-1];
}
# | 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... |