結果

問題 No.955 ax^2+bx+c=0
コンテスト
ユーザー k
提出日時 2020-12-30 16:53:23
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 929µs
コード長 1,034 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,388 ms
コンパイル使用メモリ 211,412 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-10-19 21:53:41
合計ジャッジ時間 5,935 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge6_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 123
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  long double a, b, c;
  cin >> a >> b >> c;
  
  if (a == 0) {
    if (b != 0) {
      cout << 1 << endl;
      cout << fixed << setprecision(12) << -c/b << endl;
    } else {
      if (c == 0)
        cout << -1 << endl;
      else
        cout << 0 << endl;
    }
  } else {
    double d = b*b - 4*a*c;
    if (d < 0) {
      cout << 0 << endl;
    } else if (d == 0) {
      cout << 1 << endl;
      cout << fixed << setprecision(12) << -b/(2*a) << endl;
    } else {
      cout << 2 << endl;

      double x1, x2;
      if (b >= 0) {
        x1 = (-2 * c) / (b + sqrt(d));
        x2 = (-b - sqrt(d)) / (2 * a);
      } else {
        x1 = (-b + sqrt(d)) / (2 * a);
        x2 = (-2 * c) / (b - sqrt(d));
      }

      cout << fixed << setprecision(12) << min(x1,x2) << endl;
      cout << fixed << setprecision(12) << max(x1,x2) << endl;      
    }
  }
  
  return 0;
}
0