結果

問題 No.1305 Speak of the Devil
ユーザー fukafukatanifukafukatani
提出日時 2020-12-04 23:08:37
言語 Rust
(1.72.1)
結果
WA  
実行時間 -
コード長 1,032 bytes
コンパイル時間 1,348 ms
コンパイル使用メモリ 151,856 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-13 12:05:14
合計ジャッジ時間 3,646 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 1 ms
4,352 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 3 ms
4,352 KB
testcase_16 AC 161 ms
4,352 KB
testcase_17 AC 162 ms
4,348 KB
testcase_18 AC 162 ms
4,352 KB
testcase_19 AC 156 ms
4,348 KB
testcase_20 AC 152 ms
4,352 KB
testcase_21 AC 157 ms
4,348 KB
testcase_22 AC 161 ms
4,348 KB
testcase_23 AC 155 ms
4,352 KB
testcase_24 AC 155 ms
4,356 KB
testcase_25 AC 151 ms
4,348 KB
testcase_26 AC 156 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<f64>();
    let (p, q) = (v[0], v[1]);
    if p == 1.0 {
        println!("1");
        return;
    }
    let mut ans = 0.0;
    let mut coef = 1.0;
    for i in 1..1000000 {
        ans += i as f64 * coef / p;
        coef = coef * (1.0 - 1.0 / p);
    }
    ans = f64::min(ans, q);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
0