結果
| 問題 |
No.955 ax^2+bx+c=0
|
| コンテスト | |
| ユーザー |
ngtkana
|
| 提出日時 | 2020-03-28 01:26:39 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,316 bytes |
| コンパイル時間 | 2,893 ms |
| コンパイル使用メモリ | 201,228 KB |
| 最終ジャッジ日時 | 2025-01-09 10:36:06 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 121 WA * 1 |
コンパイルメッセージ
main.cpp: In lambda function:
main.cpp:34:27: warning: narrowing conversion of ‘c’ from ‘const lint’ {aka ‘const long long int’} to ‘real’ {aka ‘long double’} [-Wnarrowing]
34 | return {-real{c}/b};
| ^
main.cpp:34:27: warning: narrowing conversion of ‘(lint)c’ from ‘lint’ {aka ‘long long int’} to ‘real’ {aka ‘long double’} [-Wnarrowing]
main.cpp:37:22: warning: narrowing conversion of ‘b’ from ‘const lint’ {aka ‘const long long int’} to ‘real’ {aka ‘long double’} [-Wnarrowing]
37 | real x=-real{b}/(2*a);
| ^
main.cpp:37:22: warning: narrowing conversion of ‘(lint)b’ from ‘lint’ {aka ‘long long int’} to ‘real’ {aka ‘long double’} [-Wnarrowing]
ソースコード
#include<bits/stdc++.h>
using lint=long long;
using real=long double;
void debug_impl(){std::cerr<<'\n';}
template<class Head,class...Tail>void debug_impl(Head head, Tail... tail){std::cerr << " " << head;debug_impl(tail...);}
template<class Container,class Value=typename Container::value_type,std::enable_if_t<!std::is_same<Container,std::string>::value,std::nullptr_t> = nullptr>
std::ostream&operator<<(std::ostream&os,Container const&v)
{os<<"{";for(auto it=v.begin();it!=v.end();it++){os<<(it!=v.begin()?",":"")<<*it;}return os<<"}";}
template<template<class...>class Tuple,class...Args,std::size_t...Inds,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&tuple_output_impl(std::ostream&os,const Tuple<Args...>&tuple,std::integer_sequence<std::size_t,Inds...>)
{os<<"(";(void)std::initializer_list<int>{((void)(os<<(Inds>0?",":"")<<std::get<Inds>(tuple)),0)...};return os<<")";}
template<template<class...>class Tuple,class...Args,std::size_t=std::tuple_size<Tuple<Args...>>::value>
std::ostream&operator<<(std::ostream&os,const Tuple<Args...>&tuple)
{return tuple_output_impl(os,tuple,std::index_sequence_for<Args...>());}
#define DEBUG 1
#if DEBUG
#define debug(...)do{std::cerr<<std::boolalpha<<"["<<#__VA_ARGS__<<"]:";debug_impl(__VA_ARGS__);std::cerr<<std::noboolalpha;}while(false)
#else
#define debug(...) {}
#endif
int main(){
std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
std::cout.setf(std::ios_base::fixed);std::cout.precision(30);
lint a,b,c;std::cin>>a>>b>>c;
auto ans=[a,b,c]()->std::vector<real>{
if(a==0){
if(b==0){
if(c==0){
std::cout<<-1<<'\n';
exit(0);
}
return {};
}
return {-real{c}/b};
}
lint D=b*b-4*a*c;
real x=-real{b}/(2*a);
if(D<0)return {};
if(D==0)return {x};
real y=real{4}*a*c/(b*b);
debug(x,y);
std::vector<real>ans(2);
ans.at(0)=x*(1+std::sqrt(1-y));
ans.at(1)=std::abs(y)<1e-6
?x*(y/2+y*y/8+y*y*y/16)
:x*(1-std::sqrt(1-y));
return ans;
}();
std::sort(ans.begin(),ans.end());
std::cout<<ans.size()<<'\n';
for(real x:ans){
std::cout<<x<<'\n';
}
}
ngtkana