結果
問題 | No.2970 三次関数の絶対値 |
ユーザー |
![]() |
提出日時 | 2024-11-29 21:29:02 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 922 bytes |
コンパイル時間 | 2,124 ms |
コンパイル使用メモリ | 200,616 KB |
最終ジャッジ日時 | 2025-02-26 09:12:53 |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:23: warning: narrowing conversion of ‘L’ from ‘int’ to ‘double’ [-Wnarrowing] 9 | vector<double> X = {L, R}; | ^ main.cpp:9:23: warning: narrowing conversion of ‘L’ from ‘int’ to ‘double’ [-Wnarrowing] main.cpp:9:26: warning: narrowing conversion of ‘R’ from ‘int’ to ‘double’ [-Wnarrowing] 9 | vector<double> X = {L, R}; | ^ main.cpp:9:26: warning: narrowing conversion of ‘R’ from ‘int’ to ‘double’ [-Wnarrowing]
ソースコード
#include <bits/stdc++.h>using namespace std;const double INF = 10000000;int main(){int C0, C1, C2, C3;cin >> C0 >> C1 >> C2 >> C3;int L, R;cin >> L >> R;vector<double> X = {L, R};if (C3 != 0){double a = C3 * 3, b = C2 * 2, c = C1;if (b * b - 4 * a * c >= 0){for (int sgn : {-1, 1}){double x = (-b + sgn * sqrt(b * b - 4 * a * c)) / (2 * a);if (L <= x && x <= R){X.push_back(x);}}}} else if (C2 != 0){double x = -C1 / (C2 * 2);if (L <= x && x <= R){X.push_back(x);}}sort(X.begin(), X.end());int cnt = X.size();auto f = [&](double x){return ((x * C3 + C2) * x + C1) * x + C0;};double ans = INF;for (int i = 0; i < cnt; i++){ans = min(ans, abs(f(X[i])));}for (int i = 0; i < cnt - 1; i++){if (f(X[i]) * f(X[i + 1]) < 0){ans = 0;}}cout << ans << endl;}