結果

問題 No.550 夏休みの思い出(1)
ユーザー 0x19f
提出日時 2017-07-29 00:16:20
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 862 bytes
コンパイル時間 608 ms
コンパイル使用メモリ 65,912 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-10 07:08:10
合計ジャッジ時間 2,541 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

double A, B, C;

double f(double x) {
  return x * x * x + A * x * x + B * x + C;
}

double solve(double l, double h) {
  double m;
  if(f(l) > 0) swap(l, h);
  REP(i, 0, 200000) {
    m = (l + h) / 2.0;
    if(f(m) > 0) h = m;
    else l = m;
  }
  return m;
}

ll floorll(double r) {
  ll s = (ll) r;
  ll t = s + 1;
  return abs(r - (double) s) < abs(r - (double) t) ? s : t;
}

int main(void) {
  cin >> A >> B >> C;

  double p = (-A - sqrt(A * A - B * 3.0)) / 3.0;
  double q = (-A + sqrt(A * A - B * 3.0)) / 3.0;

  double a = solve(-1e10, p);
  double b = solve(p, q);
  double c = solve(q, 1e10);

  cout << floorll(a) << " " << floorll(b) << " " << floorll(c) << endl;
}
0