結果

問題 No.955 ax^2+bx+c=0
ユーザー yuruhiya
提出日時 2019-12-21 22:41:16
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 772 bytes
コンパイル時間 2,285 ms
コンパイル使用メモリ 193,192 KB
最終ジャッジ日時 2025-01-08 13:48:19
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 97 WA * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long a, b, c;
  cin >> a >> b >> c;
  long double A = a, B = b, C = c;
  cout << fixed << setprecision(18);
  if (a == 0 && b == 0 && c == 0) {
    cout << -1 << endl;
  } else if (a == 0 && b == 0) {
    cout << 0 << endl;
  } else if (a == 0) {
    cout << 1 << endl;
    cout << -(C / B) << endl;
  } else {
    long long D = b * b - 4 * a * c;
    if (D < 0) {
      cout << 0 << endl;
    } else if (D == 0) {
      cout << 1 << endl;
      cout << -B / (2 * A) << endl;
    } else {
      cout << 2 << endl;
      long double ans1 = (-B + sqrt(D)) / (2 * A);
      long double ans2 = (-B - sqrt(D)) / (2 * A);
      cout << min(ans1, ans2) << endl;
      cout << max(ans1, ans2) << endl;
    }
  }
}
0