use proconio::input; fn main() { input! { c:[i32;4], l:f64, r:f64, } let ans = if c[3] != 0 { solve3(&c, l, r) } else if c[2] != 0 { solve2(&c, l, r) } else if c[1] != 0 { solve1(&c, l, r) } else { 0.0 }; println!("{}", ans); } fn solve3(c: &Vec, l: f64, r: f64) -> f64 { let mut ans = f(l, &c).abs().min(f(r, &c).abs()); let d = c[2] * c[2] - 3 * c[1] * c[3]; if d >= 0 { let x_0 = (-c[2] as f64 + (d as f64).sqrt()) / (3.0 * c[3] as f64); if l <= x_0 && x_0 <= r { ans = ans.min(f(x_0, &c).abs()); } let x_1 = (-c[2] as f64 - (d as f64).sqrt()) / (3.0 * c[3] as f64); if l <= x_1 && x_1 <= r { ans = ans.min(f(x_1, &c).abs()); } if f(x_0, &c) * f(x_1, &c) < 0.0 { ans = 0.0; } } ans } fn solve2(c: &Vec, l: f64, r: f64) -> f64 { let mut ans = f(l, &c).abs().min(f(r, &c).abs()); let x = -c[1] as f64 / (2.0 * c[2] as f64); if l<=x&&x<=r{ ans = ans.min(f(x, &c).abs()); } ans } fn solve1(c: &Vec, l: f64, r: f64) -> f64 { let ans = f(l, &c).abs().min(f(r, &c).abs()); ans } fn f(x: f64, c: &Vec) -> f64 { c[0] as f64 + c[1] as f64 * x + c[2] as f64 * x * x + c[3] as f64 * x * x * x }