結果

問題 No.1179 Quadratic Equation
ユーザー k2fontk2font
提出日時 2020-11-03 18:26:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,135 bytes
コンパイル時間 1,978 ms
コンパイル使用メモリ 199,244 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 14:54:35
合計ジャッジ時間 2,777 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
using P = pair<ll, ll>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
char inverse_char(char c) {
  if(isupper(c)) return tolower(c);
  else return toupper(c);
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
struct edge {
  ll to, cost;
};

int main() {
  double a, b, c; cin >> a >> b >> c;
  double tmp = b * b - 4 * a * c;
  if(tmp < 0) {
    cout << "imaginary" << endl;
    return 0;
  }
  double res1 = -b + sqrt(tmp); res1 /= (2 * a);
  double res2 = -b - sqrt(tmp); res2 /= (2 * a);
  if(res1 == res2) cout << fixed << setprecision(20) << res1 << endl;
  else cout << fixed << setprecision(20) << min(res1, res2) << " " << max(res1, res2) << endl;
}
0