結果

問題 No.1319 最強とんがりコーン
ユーザー koba-e964koba-e964
提出日時 2023-08-28 11:00:33
言語 Rust
(1.77.0)
結果
AC  
実行時間 36 ms / 2,000 ms
コード長 1,738 bytes
コンパイル時間 6,382 ms
コンパイル使用メモリ 142,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-28 11:00:52
合計ジャッジ時間 9,982 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
4,380 KB
testcase_01 AC 35 ms
4,376 KB
testcase_02 AC 35 ms
4,376 KB
testcase_03 AC 34 ms
4,376 KB
testcase_04 AC 34 ms
4,380 KB
testcase_05 AC 35 ms
4,376 KB
testcase_06 AC 34 ms
4,376 KB
testcase_07 AC 34 ms
4,380 KB
testcase_08 AC 35 ms
4,380 KB
testcase_09 AC 34 ms
4,380 KB
testcase_10 AC 34 ms
4,380 KB
testcase_11 AC 35 ms
4,380 KB
testcase_12 AC 34 ms
4,376 KB
testcase_13 AC 35 ms
4,376 KB
testcase_14 AC 34 ms
4,376 KB
testcase_15 AC 34 ms
4,376 KB
testcase_16 AC 34 ms
4,376 KB
testcase_17 AC 34 ms
4,380 KB
testcase_18 AC 34 ms
4,380 KB
testcase_19 AC 34 ms
4,376 KB
testcase_20 AC 34 ms
4,380 KB
testcase_21 AC 34 ms
4,376 KB
testcase_22 AC 35 ms
4,380 KB
testcase_23 AC 35 ms
4,376 KB
testcase_24 AC 34 ms
4,384 KB
testcase_25 AC 35 ms
4,376 KB
testcase_26 AC 34 ms
4,376 KB
testcase_27 AC 35 ms
4,376 KB
testcase_28 AC 34 ms
4,376 KB
testcase_29 AC 34 ms
4,380 KB
testcase_30 AC 35 ms
4,380 KB
testcase_31 AC 35 ms
4,380 KB
testcase_32 AC 35 ms
4,376 KB
testcase_33 AC 35 ms
4,380 KB
testcase_34 AC 35 ms
4,376 KB
testcase_35 AC 35 ms
4,380 KB
testcase_36 AC 35 ms
4,380 KB
testcase_37 AC 35 ms
4,376 KB
testcase_38 AC 35 ms
4,376 KB
testcase_39 AC 35 ms
4,376 KB
testcase_40 AC 34 ms
4,376 KB
testcase_41 AC 34 ms
4,380 KB
testcase_42 AC 34 ms
4,376 KB
testcase_43 AC 35 ms
4,380 KB
testcase_44 AC 33 ms
4,384 KB
testcase_45 AC 34 ms
4,376 KB
testcase_46 AC 35 ms
4,380 KB
testcase_47 AC 34 ms
4,376 KB
testcase_48 AC 34 ms
4,376 KB
testcase_49 AC 34 ms
4,380 KB
testcase_50 AC 35 ms
4,376 KB
testcase_51 AC 34 ms
4,376 KB
testcase_52 AC 34 ms
4,376 KB
testcase_53 AC 35 ms
4,380 KB
testcase_54 AC 36 ms
4,376 KB
testcase_55 AC 34 ms
4,376 KB
testcase_56 AC 33 ms
4,380 KB
testcase_57 AC 34 ms
4,376 KB
testcase_58 AC 34 ms
4,376 KB
testcase_59 AC 34 ms
4,376 KB
testcase_60 AC 11 ms
4,380 KB
testcase_61 AC 10 ms
4,380 KB
testcase_62 AC 10 ms
4,380 KB
testcase_63 AC 10 ms
4,376 KB
testcase_64 AC 35 ms
4,376 KB
testcase_65 AC 34 ms
4,376 KB
testcase_66 AC 10 ms
4,376 KB
testcase_67 AC 35 ms
4,380 KB
testcase_68 AC 35 ms
4,380 KB
testcase_69 AC 35 ms
4,376 KB
testcase_70 AC 35 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn get_word() -> String {
    let stdin = std::io::stdin();
    let mut stdin=stdin.lock();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

// Intersection of
// - 0 <= z <= 1
// - x^2 + y^2 <= (1-z)^2
// - (x-a)^2 + y^2 <= (1-z)^2
// When cut x = b (a/2 <= b <= 1), the area is sqrt(1-b^2) - b^2 ln((1+sqrt(1-b^2))/b)
fn calc(a: f64) -> f64 {
    const W: i64 = 1_000_000;
    let mut ans = 0.0;
    let width = (1.0 - a / 2.0) / W as f64;
    for i in 0..W + 1 {
        let b = 1.0 - i as f64 * width;
        let tmp = if b == 0.0 {
            1.0
        } else {
            (1.0 - b * b).sqrt() - b * b * ((1.0 + (1.0 - b * b).sqrt()) / b).ln()
        };
        if i % 2 == 1 {
            ans += tmp * 4.0;
        } else if i != 0 && i != W {
            ans += tmp * 2.0;
        } else {
            ans += tmp;
        }
    }
    ans * width * 2.0 / 3.0
}

// https://yukicoder.me/problems/no/1319 (3)
// 積分。厳密解を求めるのは面倒なので Simpson 法を使う。
// 平面 x = b で切った部分の面積は厳密に求められるので、それに対して Simpson 法を使う。
fn main() {
    let r: f64 = get();
    let h: f64 = get();
    let d: f64 = get();
    println!("{}", r * r * h * calc(d / r));
}
0