이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
#define ll long long
#define all(v) v.begin() , v.end()
#define sz(a) (ll)a.size()
using namespace std;
const ll INF = (ll) 1e18 + 5;
vector<ll> dp,ndp;
vector<array<ll,2>> v;
void f(ll l,ll r,ll optl,ll optr){
if(l>r) return;
ll mid = (l+r)/2;
ll cur = INF, best = -1;
for(ll i = min(mid,optr) ; i >= max(1LL,optl); i--){
ll b = v[mid][1];
ll a = v[i][0];
ll d = (i > 1 ? v[i - 1][1] : -INF);
if(dp[i-1] == INF) continue;
if(dp[i-1] + (b-a+1) * (b-a+1) - max(0LL,d-a+1) * max(0LL,d-a+1) < cur){
best = i;
cur = dp[i-1] + (b-a+1) * (b-a+1) - max(0LL,d-a+1) * max(0LL,d-a+1);
}
}
ndp[mid] = cur;
f(l,mid-1,optl,best) , f(mid+1,r,best,optr);
}
ll take_photos(int _n,int _m,int _k,vector<int> r,vector<int> c){
ll n = _n, m = _m, k = _k,ans = INF;
for(ll i=0;i<n;i++){
ll a=r[i],b=c[i];
if(a>b) swap(a,b);
v.push_back({a,b});
}
sort(all(v));
vector<array<ll,2>> xdd;
xdd.push_back({-1LL,-1LL});
for(ll i=0;i<n;i++){
if(v[i][0] == xdd.back()[0]){
xdd.pop_back();
xdd.push_back(v[i]);
}
else if(xdd.back()[1] < v[i][1]) xdd.push_back(v[i]);
}
swap(v,xdd);
n = sz(v) - 1;
dp.assign(n+5,INF);
dp[0] = 0;
for(ll i=1;i<=k;i++){
ndp.assign(n+5,INF);
f(1,n,1,n);
swap(dp,ndp);
ans=min(ans,dp[n]);
}
return ans;
}
/*void _(){
int n,m,k;
cin >> n >> m >> k;
for(int i=0;i<n;i++){
int a,b;
cin >> a >> b;
if(a>b) swap(a,b);
v.push_back({a,b});
}
ll ans = INF;
sort(all(v));
vector<array<ll,2>> xdd;
xdd.push_back({-1LL,-1LL});
for(int i=0;i<n;i++){
if(v[i][0] == xdd.back()[0]){
xdd.pop_back();
xdd.push_back(v[i]);
}
else if(xdd.back()[1] < v[i][1]) xdd.push_back(v[i]);
}
swap(v,xdd);
n = sz(v) - 1;
dp.assign(n+5,INF);
dp[0] = 0;
for(int i=1;i<=k;i++){
ndp.assign(n+5,INF);
f(1,n,1,n);
swap(dp,ndp);
ans=min(ans,dp[n]);
}
cout << ans << '\n';
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int tc=1;//cin >> tc;
while(tc--) _();
return 0;
}*/
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:32:14: warning: unused variable 'm' [-Wunused-variable]
32 | ll n = _n, m = _m, k = _k,ans = INF;
| ^
# | 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... |