結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
|
提出日時 | 2020-06-04 23:22:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,592 bytes |
コンパイル時間 | 1,461 ms |
コンパイル使用メモリ | 167,584 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-30 18:22:34 |
合計ジャッジ時間 | 4,183 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 93 WA * 29 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; #include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; void solve(ll a, ll b, ll c) { ld A=a; ld B=b; ld C=c; // 判別式 ld D = B*B - 4.0L*A*C; cout << fixed << setprecision(15); if(a==0 && b == 0 && c==0) { cout << "-1\n"; } else if((a==0 && b==0) || D<0) { cout << "0\n"; } else if(a==0) { // x = -c/b | a==0 cout << "1\n" << -C/B << '\n'; } else if(D<0.1) { // x = -b / 2a cout << "1\n" << -B/(2.0L*A) << '\n'; } else { ll sq = sqrt(D); ld x1 = 0; // + ld x2 = 0; // - if(b%(2*a)==0 && sq*sq==D) { x1 = b/(2*a) + static_cast<ld>(sq)/(2.0L*A); x2 = b/(2*a) - static_cast<ld>(sq)/(2.0L*A); } else if(b%(2*a)==0) { x1 = b/(2*a) + sqrt(D)/(2.0L*A); x2 = b/(2*a) - sqrt(D)/(2.0L*A); } else if(sq*sq==D) { x1 = B/(2.0L*A) + static_cast<ld>(sq)/(2.0L*A); x2 = B/(2.0L*A) - static_cast<ld>(sq)/(2.0L*A); } else { x1 = (-B + sqrt(D)) / (2.0L * A); x2 = (-B - sqrt(D)) / (2.0L * A); } cout << "2\n" << min(x1, x2) << '\n' << max(x1, x2) << '\n'; } return; } int main() { ios::sync_with_stdio(false); cin.tie(0); int a, b, c; cin >> a >> b >> c; solve(a, b, c); return 0; }