이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define v vector
#define ll long long
#define ii pair<long long,long long>
#define fi first
#define se second
v<ii> ph;
ll C(int i, int j){ // i>j, j is exclusive.
ll len = ph[i].se - ph[j+1].fi + 1;
ll intersect = max(0LL, ph[j].se - ph[j+1].fi + 1);
return len*len - intersect*intersect;
}
v<ll> dplast, dpcur;
void comp(int l, int r, int optl, int optr){
if(l>r) return;
int m=(l+r)/2;
dpcur[m] = 1e18;
int opt;
for(int i=optl; i<=min(m-1, optr); i++){
ll cur = dplast[i] + C(m,i);
if(cur<dpcur[m]){
dpcur[m]=cur;
opt=i;
}
}
comp(l,m-1,optl,opt);
comp(m+1,r,opt,optr);
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
set<ii> tmp;
for(int i=0;i<n;i++){
tmp.insert({min(r[i],c[i]),-max(c[i],r[i])});
} cin.tie(0);
ph.push_back({-1,-1});
for(ii it:tmp){
if(ph.back().se < -it.se) ph.push_back({it.fi, -it.se});
}
n=ph.size()-1;
if(n<=4000){//knuths
v<v<int>> opt(k+1, v<int>(n+2, 0));
for(int h=0; h<=k; h++) opt[h][n+1]=n;
v<v<ll>> dp(k+1, v<ll>(n+1, 1e18));
for(int h=0; h<=k; h++) dp[h][0] = 0;
for(int h=1; h<=k; h++){
for(int i=n; i>0; i--){
for(int j=opt[h-1][i]; j<=min(i-1, opt[h][i+1]); j++){
ll cost = dp[h-1][j] + C(i,j);
if(cost<dp[h][i]){
dp[h][i] = cost;
opt[h][i]=j;
}
}
}
}
return dp[k][n];
}
else{//d&c
dplast = v<ll>(n+2,0);
dpcur = v<ll>(n+2,0);
for(int i=1; i<=n; i++) dplast[i] = C(i,0);
for(int h=2; h<=k; h++){
comp(1, n, 0, n);
dplast = dpcur;
}
return dplast[n];
}
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'void comp(int, int, int, int)':
aliens.cpp:31:9: warning: 'opt' may be used uninitialized in this function [-Wmaybe-uninitialized]
31 | comp(l,m-1,optl,opt);
| ~~~~^~~~~~~~~~~~~~~~
# | 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... |