結果

問題 No.955 ax^2+bx+c=0
ユーザー risujiroh
提出日時 2019-12-18 03:12:15
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 976 bytes
コンパイル時間 1,720 ms
コンパイル使用メモリ 169,128 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-07 00:21:11
合計ジャッジ時間 3,640 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 102 WA * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using R = long double;
constexpr R eps = 1e-15;

vector<R> solve_quadratic_equation(R a, R b, R c) {
  R d = b * b - 4 * a * c;
  if (d < -eps) {
    return {};
  }
  if (d < eps) {
    return {-b / (2 * a)};
  }
  if (b < 0) {
    return {
      (b * b - d) / (-b + sqrt(d)) /  (2 * a),
      (-b + sqrt(d)) / (2 * a)
    };
  } else {
    return {
      (-b - sqrt(d)) / (2 * a),
      (b * b - d) / (-b - sqrt(d)) / (2 * a)
    };
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  long long a, b, c;
  cin >> a >> b >> c;
  if (a == 0) {
    if (b == 0) {
      if (c == 0) {
        cout << "-1\n";
      } else {
        cout << "0\n";
      }
    } else {
      cout << "1\n";
      cout << (R)-c / b;
    }
  } else {
    auto res = solve_quadratic_equation(a, b, c);
    cout << res.size() << '\n';
    for (auto e : res) {
      cout << e << '\n';
    }
  }
}
0