結果

問題 No.955 ax^2+bx+c=0
ユーザー phspls
提出日時 2020-01-11 23:36:02
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 1,373 bytes
コンパイル時間 13,017 ms
コンパイル使用メモリ 377,028 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-26 09:12:34
合計ジャッジ時間 14,831 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 122
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::Read;

fn solve(abc: Vec<f64>) {
    let ia = abc[0] as i128;
    let ib = abc[1] as i128;
    let ic = abc[2] as i128;
    let a = abc[0];
    let b = abc[1];
    let c = abc[2];
    if a == 0f64 {
        if b == 0f64 {
            if c == 0f64 {
                println!("{}", -1);
            } else {
                println!("{}", 0);
            }
        } else {
            println!("{}", 1);
            println!("{:.12}", -c / b);
        }
        return;
    }
    let temp = ib * ib - 4i128 * ia * ic;
    if temp > 0 {
        println!("{}", 2);
        let temp = temp as f64;
        let base = if b < 0f64 { (-b + temp.powf(0.5f64)) / (2.0f64 * a) } else { (-b - temp.powf(0.5f64)) / (2.0f64 * a) };
        let other = c / (a * base);
        if base < other {
            println!("{:.12}", base);
            println!("{:.12}", other);
        } else {
            println!("{:.12}", other);
            println!("{:.12}", base);
        }
    } else if temp == 0 {
        println!("{}", 1);
        println!("{:.12}", -b / (2.0f64 * a));
    } else {
        println!("{}", 0);
    }
}

fn main() {
    let mut abc = String::new();
    std::io::stdin().read_to_string(&mut abc).ok();
    let abc: Vec<f64> = abc.trim().split('\n').next().unwrap().trim().split_whitespace().map(|i| i.parse::<f64>().unwrap()).collect();
    solve(abc);
}
0