https://atcoder.jp/contests/abc385/tasks/abc385_f
原点から全てのビルを見られなければ、左から順に左隣のビルの陰にならないように高さを上げていきます。
これ、最初からf64にするとハマりますね。
// Santa Claus 2 #![allow(non_snake_case)] //////////////////// library //////////////////// fn read<T: std::str::FromStr>() -> T { let mut line = String::new(); std::io::stdin().read_line(&mut line).ok(); line.trim().parse().ok().unwrap() } fn read_vec<T: std::str::FromStr>() -> Vec<T> { read::<String>().split_whitespace() .map(|e| e.parse().ok().unwrap()).collect() } //////////////////// Point //////////////////// type Point = (i64, i64); fn read_point() -> Point { let v: Vec<i64> = read_vec(); (v[0], v[1]) } //////////////////// process //////////////////// fn read_input() -> Vec<Point> { let N: usize = read(); let points: Vec<Point> = (0..N).map(|_| read_point()).collect(); points } fn is_all_visible_from_origin(points: &Vec<Point>) -> bool { for i in 0..points.len()-1 { let (x1, H1) = points[i]; let (x2, H2) = points[i+1]; if x1 * H2 <= x2 * H1 { return false } } true } fn F(points: Vec<Point>) -> String { if is_all_visible_from_origin(&points) { return (-1).to_string() } let mut h: f64 = 0.0; for i in 0..points.len()-1 { let (x1, H1) = points[i]; let (x2, H2) = points[i+1]; if x1 as f64 * (H2 as f64 - h) <= x2 as f64 * (H1 as f64 - h) { h = ((x2 * H1 - x1 * H2) as f64) / ((x2 - x1) as f64) } } h.to_string() } fn main() { let points = read_input(); println!("{}", F(points)) }