Submission #37127913


Source Code Expand

#![allow(unused_macros, unused_imports)]
use std::cmp::*;
use std::collections::*;

// $ cp-batch freefall | diff freefall.out -
// $ cargo run --bin freefall

///
/// 12/9/2022
///
/// 23:04-
///

fn solve() -> f64 {
    let (a, b) = readln!(f64, f64);

    let (mut l, mut r) = (0, 10i64.pow(18) + 1);
    let f = |x| -> f64 { b * x as f64 + a / (1.0 + x as f64).sqrt() };
    while (r - l).abs() > 2 {
        let (ll, rr) = ((r + 2 * l) / 3, (2 * r + l) / 3);
        if f(ll) < f(rr) {
            r = rr;
        } else {
            l = ll;
        }
        dbgln!(l, r);
    }

    let mut res = f(l);
    for x in l..=r {
        if f(x) < res {
            res = f(x);
        }
    }
    res
}

fn main() {
    setup_out!(put, puts);

    let res = solve();
    puts!("{}", res);
}

use crate::cplib::io::*;
use crate::cplib::minmax::*;
use crate::cplib::vec::*;
// region: cplib
#[rustfmt::skip]
#[allow(dead_code)]
pub mod cplib {
pub mod io {
	macro_rules! _with_dollar_sign { ($($body:tt)*) => { macro_rules! __with_dollar_sign { $($body)* } __with_dollar_sign!($); }}
	macro_rules! setup_out {
		($fn:ident,$fn_s:ident) => {
			use std::io::Write;
			let out = std::io::stdout();
			let mut out = ::std::io::BufWriter::new(out.lock());
				_with_dollar_sign! { ($d:tt) => {
				macro_rules! $fn { ($d($format:tt)*) => { let _ = write!(out,$d($format)*); } }
				macro_rules! $fn_s { ($d($format:tt)*) => { let _ = writeln!(out,$d($format)*); } }
			}}
		};
	}
	macro_rules! _epr { ($v:expr $(,)?) => {eprint!("{} = {:?}, ", stringify!($v), $v)}; }
	macro_rules! dbgln { ($($val:expr),*) => {{ eprint!("[{}:{}] ", file!(), line!()); ($(_epr!($val)),*); eprintln!(); }}; }
	pub fn readln_str() -> String {
		let mut line = String::new();
		::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
		line
	}
	macro_rules! _read {
		($it:ident; [char]) => { _read!($it; String).chars().collect::<Vec<_>>() };
		($it:ident; [u8]) => { Vec::from(_read!($it; String).into_bytes()) };
		($it:ident; usize1) => { $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1 };
		($it:ident; [usize1]) => { $it.map(|s| s.parse::<usize>().unwrap_or_else(|e| panic!("{}", e)) - 1).collect::<Vec<_>>() };
		($it:ident; [$t:ty]) => { $it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>() };
		($it:ident; $t:ty) => { $it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e)) };
		($it:ident; $($t:tt),+) => { ($(_read!($it; $t)),*) };
	}
	macro_rules! readlns {
		($($t:tt),*; $n:expr) => {{ let stdin = ::std::io::stdin();
			::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
				let line = line.unwrap(); #[allow(unused_mut)]let mut it = line.split_whitespace(); _read!(it; $($t),*)
			}).collect::<Vec<_>>()
		}};
	}
	macro_rules! readln {
		($($t:tt),*) => {{ let line = cplib::io::readln_str(); #[allow(unused_mut)]let mut it = line.split_whitespace(); _read!(it; $($t),*) }};
	}
	pub(crate) use {readlns, readln, setup_out, dbgln, _with_dollar_sign, _epr, _read};
}
pub mod minmax {
	pub trait SetMinMax {
		fn setmin(&mut self, other: Self) -> bool;
		fn setmax(&mut self, other: Self) -> bool;
	}
	macro_rules! _set { ($self:ident, $cmp:tt, $other:ident) => {{
			let update = $other $cmp *$self;
			if update { *$self = $other; }
			update
	}}; }
	impl<T> SetMinMax for T where T: PartialOrd {
		fn setmin(&mut self, other: T) -> bool { _set!(self, <, other) }
		fn setmax(&mut self, other: T) -> bool { _set!(self, >, other) }
	}
}
pub mod vec {
	pub trait CollectVec: Iterator { fn collect_vec(self) -> Vec<Self::Item> where Self: Sized { self.collect() } }
	impl<T> CollectVec for T where T: Iterator {}
	macro_rules! vvec {
		($v:expr; $n:expr) => { Vec::from(vec![$v; $n]) };
		($v:expr; $n:expr $(; $ns:expr)+) => { Vec::from(vec![vvec![$v $(; $ns)*]; $n]) };
	}
	pub(crate) use vvec;
}
}
// endregion: cplib

Submission Info

Submission Time
Task D - Freefall
User kumalimak
Language Rust (1.42.0)
Score 400
Code Size 4106 Byte
Status AC
Exec Time 12 ms
Memory 2240 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 42
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_00.txt, 01_random_01.txt, 01_random_02.txt, 01_random_03.txt, 01_random_04.txt, 02_a_small_b_small_00.txt, 02_a_small_b_small_01.txt, 02_a_small_b_small_02.txt, 02_a_small_b_small_03.txt, 02_a_small_b_small_04.txt, 03_a_large_b_large_00.txt, 03_a_large_b_large_01.txt, 03_a_large_b_large_02.txt, 03_a_large_b_large_03.txt, 03_a_large_b_large_04.txt, 04_a_small_b_large_00.txt, 04_a_small_b_large_01.txt, 04_a_small_b_large_02.txt, 04_a_small_b_large_03.txt, 04_a_small_b_large_04.txt, 05_a_large_b_small_00.txt, 05_a_large_b_small_01.txt, 05_a_large_b_small_02.txt, 05_a_large_b_small_03.txt, 05_a_large_b_small_04.txt, 05_a_large_b_small_05.txt, 05_a_large_b_small_06.txt, 05_a_large_b_small_07.txt, 05_a_large_b_small_08.txt, 05_a_large_b_small_09.txt, 06_argmin_integer_00.txt, 06_argmin_integer_01.txt, 06_argmin_integer_02.txt, 06_argmin_integer_03.txt, 06_argmin_integer_04.txt, 07_min_00.txt, 08_max_00.txt, 08_max_01.txt, 08_max_02.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 3 ms 2024 KiB
00_sample_01.txt AC 4 ms 2120 KiB
00_sample_02.txt AC 5 ms 2124 KiB
01_random_00.txt AC 7 ms 2220 KiB
01_random_01.txt AC 4 ms 2028 KiB
01_random_02.txt AC 4 ms 2100 KiB
01_random_03.txt AC 8 ms 2068 KiB
01_random_04.txt AC 9 ms 2232 KiB
02_a_small_b_small_00.txt AC 6 ms 2204 KiB
02_a_small_b_small_01.txt AC 4 ms 2108 KiB
02_a_small_b_small_02.txt AC 8 ms 2212 KiB
02_a_small_b_small_03.txt AC 5 ms 2148 KiB
02_a_small_b_small_04.txt AC 5 ms 2140 KiB
03_a_large_b_large_00.txt AC 6 ms 2140 KiB
03_a_large_b_large_01.txt AC 7 ms 2160 KiB
03_a_large_b_large_02.txt AC 10 ms 2180 KiB
03_a_large_b_large_03.txt AC 6 ms 2180 KiB
03_a_large_b_large_04.txt AC 6 ms 2128 KiB
04_a_small_b_large_00.txt AC 5 ms 2200 KiB
04_a_small_b_large_01.txt AC 4 ms 2176 KiB
04_a_small_b_large_02.txt AC 4 ms 2128 KiB
04_a_small_b_large_03.txt AC 6 ms 2064 KiB
04_a_small_b_large_04.txt AC 5 ms 2000 KiB
05_a_large_b_small_00.txt AC 5 ms 2144 KiB
05_a_large_b_small_01.txt AC 6 ms 2168 KiB
05_a_large_b_small_02.txt AC 4 ms 2208 KiB
05_a_large_b_small_03.txt AC 6 ms 2004 KiB
05_a_large_b_small_04.txt AC 6 ms 2112 KiB
05_a_large_b_small_05.txt AC 6 ms 2124 KiB
05_a_large_b_small_06.txt AC 4 ms 2104 KiB
05_a_large_b_small_07.txt AC 7 ms 2184 KiB
05_a_large_b_small_08.txt AC 5 ms 2148 KiB
05_a_large_b_small_09.txt AC 6 ms 2180 KiB
06_argmin_integer_00.txt AC 7 ms 2240 KiB
06_argmin_integer_01.txt AC 6 ms 2132 KiB
06_argmin_integer_02.txt AC 6 ms 2176 KiB
06_argmin_integer_03.txt AC 8 ms 2140 KiB
06_argmin_integer_04.txt AC 4 ms 2088 KiB
07_min_00.txt AC 12 ms 2072 KiB
08_max_00.txt AC 5 ms 2124 KiB
08_max_01.txt AC 6 ms 2128 KiB
08_max_02.txt AC 7 ms 2180 KiB