This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define pb push_back
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 1e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cout << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cout << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cout << endl;}
ll dp[5010];
struct Line{
vector<pll> l;
int cur=0;
double cross(pll a, pll b){
return (double)(b.se-a.se)/(double)(a.fi-b.fi);
}
void add(ll a, ll b){
pll nl = pll(a,b);
while(l.size()>=2&&cross(l[l.size()-2],l[l.size()-1])>=cross(l[l.size()-2],nl)) l.pop_back();
l.push_back(nl);
}
ll get(ll x){
while(cur+1<l.size()&&cross(l[cur],l[cur+1])<=(double)x) cur++;
if(cur>=l.size()) return 0;
return l[cur].fi*x+l[cur].se;
}
}lines[5010];
ll take_photos(int n, int m, int k, vector<int>x, vector<int>y){
k=min(n,k);
vector<pll> tmp,p;
for(int i=0;i<n;i++){
if(x[i]>y[i]) swap(x[i], y[i]);
tmp.pb({x[i],y[i]});
}
sort(tmp.begin(), tmp.end(), [](pii a, pii b){if(a.se==b.se) return a.fi>b.fi;return a.se<b.se;});
p.pb({-1,-1});
for(auto i:tmp){
while(!p.empty()&&p[p.size()-1].fi>=i.fi) p.pop_back();
p.pb(i);
}
lines[0].add(-2*(p[1].fi-1),(p[1].fi-1)*(p[1].fi-1));
for(int i=1;i<(int)p.size();i++){
for(int j=1;j<k;j++){
if(p[i].fi<=p[i-1].se) lines[j].add(-2*(p[i].fi-1),dp[j]+(p[i].fi-1)*(p[i].fi-1) - (p[i-1].se-p[i].fi+1)*(p[i-1].se-p[i].fi+1));
else lines[j].add(-2*(p[i].fi-1),dp[j]+(p[i].fi-1)*(p[i].fi-1));
}
for(int j=1;j<=k;j++){
dp[j]=lines[j-1].get(p[i].se)+p[i].se*p[i].se;
}
}
return dp[k];
}
Compilation message (stderr)
aliens.cpp: In member function 'll Line::get(ll)':
aliens.cpp:39:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(cur+1<l.size()&&cross(l[cur],l[cur+1])<=(double)x) cur++;
~~~~~^~~~~~~~~
aliens.cpp:40:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(cur>=l.size()) return 0;
~~~^~~~~~~~~~
# | 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... |