結果
| 問題 | No.2970 三次関数の絶対値 |
| コンテスト | |
| ユーザー |
umezo
|
| 提出日時 | 2024-11-29 22:16:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,325 bytes |
| 記録 | |
| コンパイル時間 | 2,785 ms |
| コンパイル使用メモリ | 246,352 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-11-29 22:16:26 |
| 合計ジャッジ時間 | 3,997 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 WA * 3 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
template <class T> using V=vector<T>;
template <class T> using VV=V<V<T>>;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int c0,c1,c2,c3,l,r;
cin>>c0>>c1>>c2>>c3>>l>>r;
auto f=[&](double x)->double{
return c0+c1*x+c2*x*x+c3*x*x*x;
};
double L=f(l),R=f(r);
if(c3!=0){
if(c2*c2-3*c1*c3>0){
double d=sqrt(c2*c2-3*c1*c3);
double x0=(-c2+d)/(3*c3),x1=(-c2-d)/(3*c3);
double mi=min(L,R),ma=max(L,R);
if(l<x0 && x0<r) mi=min(mi,f(x0)),ma=max(ma,f(x0));
if(l<x1 && x1<r) mi=min(mi,f(x1)),ma=max(ma,f(x1));
if(mi*ma<=0) cout<<0<<endl;
else printf("%.10f\n",min(abs(mi),abs(ma)));
}
else{
if(L*R<=0) cout<<0<<endl;
else printf("%.10f\n",min(abs(L),abs(R)));
}
}
else if(c2!=0){
double x2=-c1/(2*c2);
double mi=min(L,R),ma=max(L,R);
if(l<x2 && x2<r) mi=min(mi,f(x2)),ma=max(ma,f(x2));
if(mi*ma<=0) cout<<0<<endl;
else printf("%.10f\n",min(abs(mi),abs(ma)));
}
else if(c1!=0){
double mi=min(L,R),ma=max(L,R);
if(mi*ma<=0) cout<<0<<endl;
else printf("%.10f\n",min(abs(mi),abs(ma)));
}
else cout<<abs(c0)<<endl;
return 0;
}
umezo