# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72491 | IDxTree (#118) | Hill Reconstruction (FXCUP3_hill) | C++17 | 1578 ms | 42960 KiB |
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>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int inf=2e9, MX=300010;
struct edge{
ll x=1, y=0;
bool operator > (const edge &e) const {
return y*e.x>e.y*x;
}
bool operator == (const edge &e) const {
return y*e.x==e.y*x;
}
};
struct node1{
int idx; edge e;
bool operator < (const node1 &nd) const {
return idx<nd.idx;
}
};
struct node2{
int idx; edge e;
bool operator > (const node2 &nd) const {
return e>nd.e || (e==nd.e && idx>nd.idx);
}
};
set<node1> S1;
set<node2, greater<node2>> S2;
int n;
ll X[MX], Y[MX];
ll c;
int gcd(int x, int y){
if(y==0) return x;
return gcd(y,x%y);
}
ll area(int l, int r){
return (X[r]-X[l])*(Y[l]+Y[r]);
}
int main(){
scanf("%d%lld", &n, &c);
c*=2;
for(int i=1; i<=n; i++) scanf("%lld", &X[i]);
for(int i=1; i<=n; i++) scanf("%lld", &Y[i]);
for(int i=1; i<n; i++){
edge e;
e.x=X[i+1]-X[i];
e.y=Y[i+1]-Y[i];
S1.insert({i,e});
S2.insert({i,e});
}
while(true){
node2 a=*S2.begin();
int i=a.idx; edge e=a.e;
if(i==1) break;
node1 b=*prev(S1.find({i,e}));
int j=b.idx; edge f=b.e;
int k=n;
auto it=S1.find({i,e});
if(next(it)!=S1.end()) k=next(it)->idx;
ll now=area(j,k)-area(j,i)-area(i,k);
if(now>c) break;
// cout<<"POINTS: "<<j<<' '<<i<<' '<<k<<'\n';
c-=now;
S1.erase({i,e}), S2.erase({i,e});
S1.erase({j,f}), S2.erase({j,f});
edge g; g.x=e.x+f.x, g.y=e.y+f.y;
S1.insert({j,g}), S2.insert({j,g});
// cout<<S1.size()<<", "<<S2.size()<<'\n';
}
{
edge ans=S2.begin()->e;
int x=ans.x, y=ans.y, g=gcd(x,y);
printf("%lld/%lld\n", y/g,x/g);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |