結果
問題 | No.955 ax^2+bx+c=0 |
ユーザー |
|
提出日時 | 2020-04-17 21:10:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,125 bytes |
コンパイル時間 | 2,749 ms |
コンパイル使用メモリ | 198,884 KB |
最終ジャッジ日時 | 2025-01-09 19:39:42 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 121 WA * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = int64_t; int main() { ll a,b,c; cin>>a>>b>>c; if (a==0) { if (b==0) { cout<<(c==0?-1:0)<<endl; } else { cout<<1<<endl; cout <<fixed<<setprecision(15)<< double(-c) / b << endl; } return 0; } ll d = b*b - 4*a*c; if (d < 0) { cout<<0<<endl; return 0; } else if (d == 0) { cout<<1<<endl; double a2 = 2.0 * a; cout <<fixed<<setprecision(15)<< double(-b) / a2 << endl; } else { cout<<2<<endl; if (c == 0) { cout <<fixed<<setprecision(15)<< 0 << endl; cout <<fixed<<setprecision(15)<< double(-b) / a << endl; return 0; } long double a2 = 2.0 * a; long double c2 = 2.0 * c; vector<long double> res; long double ldd = d; if (b < 0) { res.push_back(c2 / (-b + sqrt(ldd))); res.push_back((-b + sqrt(ldd)) / a2); } else { res.push_back(c2 / (-b - sqrt(ldd))); res.push_back((-b - sqrt(ldd)) / a2); } sort(begin(res), end(res)); for(auto&& v:res) { cout <<fixed<<setprecision(15)<<v<<endl; } } return 0; }