結果
問題 | No.2970 三次関数の絶対値 |
ユーザー |
![]() |
提出日時 | 2024-11-29 21:26:43 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,063 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 201,680 KB |
最終ジャッジ日時 | 2025-02-26 09:11:06 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 WA * 9 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:25: warning: narrowing conversion of ‘L’ from ‘int’ to ‘double’ [-Wnarrowing] 12 | vector<double> X = {L, R}; | ^ main.cpp:12:25: warning: narrowing conversion of ‘L’ from ‘int’ to ‘double’ [-Wnarrowing] main.cpp:12:28: warning: narrowing conversion of ‘R’ from ‘int’ to ‘double’ [-Wnarrowing] 12 | vector<double> X = {L, R}; | ^ main.cpp:12:28: 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;if (C3 == 0 && C2 == 0 && C1 == 0){cout << abs(C0) << endl;} else {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;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;}}