結果
| 問題 |
No.1179 Quadratic Equation
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-21 22:19:48 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 882 bytes |
| コンパイル時間 | 1,517 ms |
| コンパイル使用メモリ | 168,716 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-15 05:50:19 |
| 合計ジャッジ時間 | 2,065 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
constexpr char newl = '\n';
// https://atcoder.jp/contests/tricky/submissions/15103401
void solve(){
ll a,b,c; scanf("%lld%lld%lld",&a,&b,&c);
if(a==0){
if(b==0){
if(c==0) puts("3");
else puts("imaginary");
}
else{
printf("%.15f\n",-1.0*c/b);
}
}
else{
if(b*b%4==0 && b*b/4==a*c){
printf("%.15f\n",-b/(2.0*a));
}
else if(b*b/4>=a*c){
double d=(b/2.0)*(b/2.0)-a*c;
double sol[2];
if(b>0){
sol[0]=(-b/2.0-sqrt(d))/a;
sol[1]=-c/(b/2.0+sqrt(d));
}
else{ // b<0
sol[0]=-c/(b/2.0-sqrt(d));
sol[1]=(-b/2.0+sqrt(d))/a;
}
sort(sol,sol+2);
printf("%.15f %.15f\n",sol[0],sol[1]);
}
else{
puts("imaginary");
}
}
}
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
solve();
return 0;
}