Submission #72512

#TimeUsernameProblemLanguageResultExecution timeMemory
72512IDxTree (#118)Hill Reconstruction (FXCUP3_hill)C++17
32 / 100
1516 ms38224 KiB
#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; } }; edge E[MX]; struct node{ int idx; bool operator > (const node &nd) const { int a=idx, b=nd.idx; ll p=E[a].y*E[b].x, q=E[b].y*E[a].x; return p>q || (p==q && a > b); } }; set<int> S1; set<node, greater<node>> 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); } inline ll area(int l, int r){ return (X[r]-X[l])*(Y[l]+Y[r]); } int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n>>c; c*=2; for(int i=1; i<=n; i++) cin>>X[i]; for(int i=1; i<=n; i++) cin>>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]; E[i]=e; } for(int i=1; i<n; i++){ S1.insert(i); S2.insert({i}); } while(true){ int i=S2.begin()->idx; if(i==1) break; int j=*prev(S1.find(i)); int k=n; auto it=S1.find(i); if(next(it)!=S1.end()) k=*next(it); 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), S2.erase({i}); S1.erase(j), S2.erase({j}); edge g; g.x=E[i].x+E[j].x, g.y=E[i].y+E[j].y; E[j]=g; S1.insert(j), S2.insert({j}); // cout<<S1.size()<<", "<<S2.size()<<'\n'; } { edge ans=E[S2.begin()->idx]; int x=ans.x, y=ans.y, g=gcd(x,y); cout<<y/g<<"/"<<x/g<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...