結果

問題 No.955 ax^2+bx+c=0
ユーザー ngtkana
提出日時 2020-03-28 01:40:08
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,322 bytes
コンパイル時間 3,082 ms
コンパイル使用メモリ 199,192 KB
最終ジャッジ日時 2025-01-09 10:36:19
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 107 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
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]

ソースコード

diff #

#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)=(-b-std::sqrt(D))/(2*a);
        ans.at(1)=std::abs(y)<1e-6
            ?x*(y/2+y*y/8+y*y*y/16)
            :(-b+std::sqrt(D))/(2*a);
        return ans;
    }();
    std::sort(ans.begin(),ans.end());
    std::cout<<ans.size()<<'\n';
    for(real x:ans){
        std::cout<<x<<'\n';
    }
}

0