結果
問題 |
No.955 ax^2+bx+c=0
|
ユーザー |
|
提出日時 | 2024-01-04 22:59:00 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 1,962 bytes |
コンパイル時間 | 7,935 ms |
コンパイル使用メモリ | 350,008 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-27 18:51:10 |
合計ジャッジ時間 | 10,730 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 122 |
ソースコード
#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; #define rep(i,m,n,k) for (int i = (int)(m); i < (int)(n); i += (int)(k)) #define rrep(i,m,n,k) for (int i = (int)(m); i > (int)(n); i += (int)(k)) #define ll long long #define list(T,A,N) vector<T> A(N);for(int i=0;i<(int)(N);i++){cin >> A[i];} template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;} template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;} int main(){ long long a,b,c; cin >> a >> b >> c; if(a==0){ if(b==0){ if(c==0){ cout << -1 << endl; return 0; } else{ cout << 0 << endl; return 0; } } else{ cout << 1 << endl; cout << fixed << setprecision(12); cout << -(long double)c/(long double)b << endl; return 0; } } else{ long long D = b*b - 4*a*c; if(D==0){ cout << 1 << endl; cout << fixed << setprecision(12); cout << - (long double)b/(long double)(2*a) << endl; return 0; } else if (D<0){ cout << 0 << endl; return 0; } else{ long double x; if(b>0){ x = ((long double)(-b) - sqrt((long double)D))/(long double)(2*a); } else{ x = ((long double)(-b) + sqrt((long double)D))/(long double)(2*a); } long double y = (long double)c/(long double)(a)/x; cout << 2 << endl; cout << fixed << setprecision(12); cout << min(x,y) << endl; cout << max(x,y) << endl; return 0; } } }