이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define RE(a,b) REP(a,0,b)
#define FOR(a,b) for(auto& a:b)
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
const int INF=1e9;
const int MX=2e5;
vi r, c, le, ri;
int n, m, k;
int SA[MX];
vll dp, odp;
ll getCost(int i, int j) {
ll w = ri[j]-le[i]+1;
ll res = w*w;
if(j != n-1) {
ll sw = ri[j]-le[j+1]+1;
if(sw > 0)
res -= sw*sw;
}
return res;
}
void computeDP(int l, int r, int optl, int optr) {
if(r < l) return;
int m = (l+r)/2;
int opt = -1;
dp[m] = 1e18;
REP(j,optl,min(optr+1,m)) {
ll ndp = odp[j] + getCost(j,m-1);
if(ndp < dp[m]) {
dp[m] = ndp;
opt = j;
}
}
computeDP(l, m-1, optl, opt);
computeDP(m+1, r, opt, optr);
}
ll take_photos(int _n, int _m, int _k, vi _r, vi _c) {
n=_n; m=_m; k=_k; r=_r; c=_c;
RE(i,n) if(c[i] < r[i]) swap(c[i], r[i]);
RE(i,n) SA[i] = i;
sort(SA,SA+n,[](int i, int j) {
if(r[i] == r[j]) return c[i] > c[j];
return r[i] < r[j];
});
ll mxr = -1;
RE(i,n) {
if(c[SA[i]] <= mxr) continue;
le.pb(r[SA[i]]);
ri.pb(c[SA[i]]);
mxr = c[SA[i]];
}
n = le.size();
if(k > n) k = n;
dp.assign(n+1,1e18); dp[0] = 0;
REP(i,1,k+1) {
odp = dp;
computeDP(1,n,0,n-1);
}
return dp[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... |