結果
問題 | No.2970 三次関数の絶対値 |
ユーザー |
![]() |
提出日時 | 2024-12-01 22:17:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 1,016 bytes |
コンパイル時間 | 1,949 ms |
コンパイル使用メモリ | 195,328 KB |
最終ジャッジ日時 | 2025-02-26 10:16:43 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 50 |
ソースコード
#include <bits/stdc++.h> using namespace std; void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); } int main() { fast_io(); int c0, c1, c2, c3; cin >> c0 >> c1 >> c2 >> c3; int l, r; cin >> l >> r; auto f = [&](double x) { return c0 + c1 * x + c2 * x * x + c3 * x * x * x; }; double mi = min(f(l), f(r)); double ma = max(f(l), f(r)); double d0 = c1, d1 = 2 * c2, d2 = 3 * c3; if (d2 != 0) { double D = d1 * d1 - 4 * d0 * d2; if (D > 0) { double x1 = (-d1 + sqrt(D)) / (2 * d2); double x2 = (-d1 - sqrt(D)) / (2 * d2); if (x1 > l && x1 < r) { mi = min(mi, f(x1)); ma = max(ma, f(x1)); } if (x2 > l && x2 < r) { mi = min(mi, f(x2)); ma = max(ma, f(x2)); } } } else if (d1 != 0) { double x = -d0 / d1; if (x > l && x < r) { mi = min(mi, f(x)); ma = max(ma, f(x)); } } if (mi <= 0 && ma >= 0) { cout << setprecision(16) << fixed << 0.0 << endl; } else { cout << setprecision(16) << fixed << min(abs(mi), abs(ma)) << endl; } }