結果
問題 | No.2970 三次関数の絶対値 |
ユーザー |
![]() |
提出日時 | 2024-11-29 21:33:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 954 bytes |
コンパイル時間 | 2,322 ms |
コンパイル使用メモリ | 200,536 KB |
最終ジャッジ日時 | 2025-02-26 09:13:33 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 WA * 3 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:10:23: warning: narrowing conversion of ‘L’ from ‘int’ to ‘double’ [-Wnarrowing] 10 | vector<double> X = {L, R}; | ^ main.cpp:10:23: warning: narrowing conversion of ‘L’ from ‘int’ to ‘double’ [-Wnarrowing] main.cpp:10:26: warning: narrowing conversion of ‘R’ from ‘int’ to ‘double’ [-Wnarrowing] 10 | vector<double> X = {L, R}; | ^ main.cpp:10:26: warning: narrowing conversion of ‘R’ from ‘int’ to ‘double’ [-Wnarrowing]
ソースコード
#include <bits/stdc++.h> using namespace std; const double INF = 10000000; const double eps = 0.0000001; 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]) < eps){ ans = 0; } } cout << ans << endl; }