結果
| 問題 |
No.2970 三次関数の絶対値
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-06 23:04:47 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,366 bytes |
| コンパイル時間 | 14,229 ms |
| コンパイル使用メモリ | 378,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-06 23:06:26 |
| 合計ジャッジ時間 | 12,611 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 37 WA * 13 |
ソースコード
use proconio::input;
fn main() {
input! {
c:[i32;4],
l:f64,
r:f64,
}
let ans = if c[3] != 0 {
solve3(&c, l, r)
} else if c[2] != 0 {
solve2(&c, l, r)
} else if c[1] != 0 {
solve1(&c, l, r)
} else {
0.0
};
println!("{}", ans);
}
fn solve3(c: &Vec<i32>, l: f64, r: f64) -> f64 {
let mut ans = f(l, &c).abs().min(f(r, &c).abs());
let d = c[2] * c[2] - 3 * c[1] * c[3];
if d >= 0 {
let x_0 = (-c[2] as f64 + (d as f64).sqrt()) / (3.0 * c[3] as f64);
if l <= x_0 && x_0 <= r {
ans = ans.min(f(x_0, &c).abs());
}
let x_1 = (-c[2] as f64 - (d as f64).sqrt()) / (3.0 * c[3] as f64);
if l <= x_1 && x_1 <= r {
ans = ans.min(f(x_1, &c).abs());
}
if f(x_0, &c) * f(x_1, &c) < 0.0 {
ans = 0.0;
}
}
ans
}
fn solve2(c: &Vec<i32>, l: f64, r: f64) -> f64 {
let mut ans = f(l, &c).abs().min(f(r, &c).abs());
let x = -c[1] as f64 / (2.0 * c[2] as f64);
if l<=x&&x<=r{
ans = ans.min(f(x, &c).abs());
}
ans
}
fn solve1(c: &Vec<i32>, l: f64, r: f64) -> f64 {
let ans = f(l, &c).abs().min(f(r, &c).abs());
ans
}
fn f(x: f64, c: &Vec<i32>) -> f64 {
c[0] as f64 + c[1] as f64 * x + c[2] as f64 * x * x + c[3] as f64 * x * x * x
}