結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー |
![]() |
提出日時 | 2019-12-18 12:57:45 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 1,326 bytes |
コンパイル時間 | 16,494 ms |
コンパイル使用メモリ | 378,408 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-18 22:10:35 |
合計ジャッジ時間 | 16,961 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
ソースコード
use std::io::Read; fn run() { let mut s = String::new(); std::io::stdin().read_to_string(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let mut a: i64 = it.next().unwrap().parse().unwrap(); let mut b: i64 = it.next().unwrap().parse().unwrap(); let mut c: i64 = it.next().unwrap().parse().unwrap(); if a == 0 { if b == 0 { if c == 0 { println!("-1"); } else { println!("0"); } } else { let ans = -c as f64 / b as f64; println!("1\n{:.12}", ans); } return; } let d = b * b - 4 * a * c; if d < 0 { println!("0"); return; } if d == 0 { let ans = -b as f64 / (2 * a) as f64; println!("1\n{:.12}", ans); return; } if a < 0 { a *= -1; b *= -1; c *= -1; } if b > 0 { let x = (-b as f64 - (d as f64).sqrt()) / (2 * a) as f64; let y = (2 * c) as f64 / (-b as f64 - (d as f64).sqrt()); println!("2\n{:.12}\n{:.12}", x, y); } else { let x = (2 * c) as f64 / (-b as f64 + (d as f64).sqrt()); let y = (-b as f64 + (d as f64).sqrt()) / (2 * a) as f64; println!("2\n{:.12}\n{:.12}", x, y); } } fn main() { run(); }