結果

問題 No.550 夏休みの思い出(1)
ユーザー nanophoto12
提出日時 2017-07-30 18:13:38
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,460 bytes
コンパイル時間 1,006 ms
コンパイル使用メモリ 94,496 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 22:35:45
合計ジャッジ時間 2,425 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 48 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

#define ll long long int

struct binarysearch
{
    const int maxLoop = 128;
    
    const function<double(double)> f;
    
    binarysearch(function<double(double)> func) : f(func)
    {
    }
    
    double search(double left, double right)
    {
        for (int loop = 0; loop < maxLoop; ++loop){
            auto middle = (left + right) / 2;
            auto l = f(left);
            auto m = f(middle);
            if (l * m <= 0)
            {
                right = middle;
            } else
            {
                left = middle;
            }
        }
        return (right + left) / 2.0;
    }
};



int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    // 3x^2 + 2ax + b = 0;
    // -(2a) +
    auto left = -(2 * a + sqrt(4 * a * a - 4 * 3 * b)) / 6;
    auto right = -(2 * a - sqrt(4 * a * a - 4 * 3 * b)) / 6;
    
    binarysearch s([=](double x){ return x * x * x + a * x * x + b * x + c; });
    
    auto l = s.search(-1e11, left);
    auto m = s.search(left, right);
    auto r = s.search(right, 1e11);
    cout << (int)round(l) << " " << (int)round(m) << " " << (int)round(r) << endl;
    return 0;
}
0