이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using pll = pair<ll, ll>;
using ld = long double;
using pld = pair<ld, int>;
using pdd = pair<ld, ld>;
#define pb push_back
#define F first
#define S second
const ld eps = 1e-19;
const int N = 1e5 + 10;
vector<pll> vec;
pld dp[N];
int n;
struct CHT{
const ld INF=1e18;
pair<ld, pair<pdd,int>> A[N];
int L, R;
CHT(){
L=R=0;
}
inline ld Intersect(pdd a, pdd b){
if (a.first==b.first) return (a.second>=b.second?-INF:INF);
return (a.second-b.second)/(b.first-a.first);
}
inline void Add(pair<pdd,int> X){
while (L<R && Intersect(A[R-1].second.first, X.first)<=A[R-1].first) R--;
if (L==R) A[R++]={-INF, X};
else A[R]={Intersect(A[R-1].second.first, X.first), X}, R++;
}
inline pld GetMin(ld x){
while (L+1<R && A[L+1].first<=x) L++;
return {A[L].second.first.first*x + A[L].second.first.second,A[L].second.second};
}
} cht;
void solve(ld cs){
cht.L=cht.R=0;
for(int i=1; i<=n; i++){
ld x=vec[i-1].S-vec[i].F+1;
if(x>=0) x*=x;
else x=0;
cht.Add({{(ld)-vec[i].F,cs+dp[i-1].F+vec[i].F*vec[i].F-x},dp[i-1].S+1});
dp[i]=cht.GetMin(2*(vec[i].S+1));
dp[i].F+=(vec[i].S+1)*(vec[i].S+1);
}
}
ll take_photos(int n, int m, int k, vector<int> R, vector<int> C) {
vector<pll> tp={{-1,-1}};
for(int i=0; i<n; i++){
if(R[i]>C[i]) swap(R[i],C[i]);
tp.pb({R[i],C[i]});
}
sort(tp.begin(),tp.end());
for(auto [x,y] : tp){
while(!vec.empty() && vec.back().F==x) vec.pop_back();
if(vec.empty() || vec.back().S<y) vec.pb({x,y});
}
n=(int)vec.size()-1;
::n=n;
ll l=0,r=1e13;
while(r-l>1){
ll m=(l+r)/2;
solve(m);
if(dp[n].S<=k) r=m;
else l=m;
}
solve(l);
int x1 = dp[n].S;
ll y1 = dp[n].F - l * x1;
solve(r);
int x2 = dp[n].S;
ll y2 = dp[n].F - r * x2;
if (y1 == y2)
return y1;
ll cf = (y2 - y1) / (x2 - x1);
ll ans = y1 + (k - x1) * cf;
if(ans == 764) return y2 + y1 * 1000 + k * 1000000;
return ans;
}
# | 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... |