# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
72463 | 유애나 (#118) | Hill Reconstruction (FXCUP3_hill) | C++17 | 348 ms | 5424 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;
using ld = long double;
using ll = long long;
const int N = 300005, TRIAL = 70;
int n;
ll a[N], b[N], c, mb, ma;
int f(ld x){
mb = 0; ma = 1;
int lst = n - 1;
ll s = 0, cs = 0;
for(int i = n - 2; i >= 0; i--){
cs += (a[i] * b[i + 1] - b[i] * a[i + 1]);
if(ld(b[lst] - b[i]) / (a[lst] - a[i]) <= x){
cs += (a[lst] * b[i] - b[lst] * a[i]);
s += abs(cs);
if(ma * (b[lst] - b[i]) > mb * (a[lst] - a[i])){
mb = b[lst] - b[i];
ma = a[lst] - a[i];
}
lst = i;
cs = 0;
}
if(s > 2 * c) return 0;
}
return !lst;
}
int main(){
scanf("%d%lld", &n, &c);
for(int i = 0; i < n; i++) scanf("%lld", a + i);
for(int i = 0; i < n; i++) scanf("%lld", b + i);
ld l = 0, r = 1e9;
for(int i = 0; i < TRIAL; i++){
ld m = (l + r) / 2;
if(f(m)) r = m;
else l = m;
}
f(l + 1e-9);
printf("%lld/%lld\n", mb / gcd(mb, ma), ma / gcd(mb, ma));
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |