#include <bits/stdc++.h>
#include "aliens.h"
using namespace std;
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
vector<pair<int,int>> tm,st;
for(int i=0;i<n;i++){
if(r[i]>c[i])swap(r[i],c[i]);
tm.push_back({r[i],c[i]});
}
sort(tm.begin(),tm.end(),[](pair<int,int> p1,pair<int,int> p2){
if(p1.first!=p2.first)return p1.first<p2.first;
return p1.second>p2.second;
});
st.push_back({-1,-1});
for(auto p:tm){
if(p.second>st.back().second)st.push_back(p);
}
n=st.size()-1;
long long dp[n+1][k+1],a[n+1],h[n+1];
for(int i=0;i<=n;i++){
a[i]=st[i].second+1;
h[i]=st[i].second-st[i].first+1;
}
for(int i=1;i<=n;i++)dp[i][0]=1e18;
for(int i=0;i<=k;i++)dp[0][i]=0;
for(int j=1;j<=k;j++){
for(int i=1;i<=n;i++){
dp[i][j]=1e18;
int idx=i;
for(long long x=h[i];x<=a[i];x++){
while(a[idx]-h[idx]>=a[i]-x)idx--;
long long len=max(0LL,x-a[i]+a[idx]);
dp[i][j]=min(dp[i][j],x*x-len*len+dp[idx][j-1]);
}
}
}
return dp[n][k];
}
Compilation message (stderr)
aliens.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
aliens_c.h:1:9: warning: #pragma once in main file
1 | #pragma once
| ^~~~
# | 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... |