結果

問題 No.550 夏休みの思い出(1)
ユーザー tnakao0123tnakao0123
提出日時 2017-07-31 18:32:57
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,810 bytes
コンパイル時間 944 ms
コンパイル使用メモリ 85,912 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-04-19 07:31:11
合計ジャッジ時間 7,300 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
testcase_48 -- -
testcase_49 -- -
testcase_50 -- -
testcase_51 -- -
testcase_52 -- -
testcase_53 -- -
testcase_54 -- -
testcase_55 -- -
testcase_56 -- -
testcase_57 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 550.cc: No.550 夏休みの思い出(1) - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

// f(x)=(x-a)(x-b)(x-c) = x^3+Ax^2+Bx+C = 0
// -> (x^2-(a+b)x+ab)(x-c) = x^3-(a+b+c)x^2+(ab+bc+ca)x-abc = 0
// A=-(a+b+c) -> -(b+c)=A+a, C=-abc -> bc=-C/a

int main() {
  ll A, B, C;
  cin >> A >> B >> C;

  ll a;
  for (a = -1000000; a <= 1000000; a++) {
    ll y = a * a * a + A * a * a + B * a + C;
    if (y == 0) break;
  }
  //printf("a=%lld\n", a);

  ll D = A + a, E = (a != 0) ? -C / a : B;
  //printf("x^2+%lldx+%lld\n", D, E);

  ll x0 = -1000000, x1 = 1000000, y0, y1;
  for (;;) {
    y0 = x0 * x0 + D * x0 + E;
    y1 = x1 * x1 + D * x1 + E;
    if (y0 <= 0 || y1 <= 0) break;
    ll x = (x0 + x1) / 2;
    if (y0 > y1) x0 = x;
    else x1 = x;
  }
  //printf("x0=%lld, x1=%lld\n", x0, x1);

  ll b;
  if (y0 == 0) b = x0;
  else if (y1 == 0) b = x1;
  else if (y0 < 0) {
    while (x0 + 1 < x1) {
      ll x = (x0 + x1) / 2;
      ll y = x * x + D * x + E;
      if (y > 0) x1 = x;
      else x0 = x;
    }
    b = x0;
  }
  else {
    while (x0 + 1 < x1) {
      ll x = (x0 + x1) / 2;
      ll y = x * x + D * x + E;
      if (y > 0) x0 = x;
      else x1 = x;
    }
    b = x1;
  }
  ll c = -(D + b);
  //printf("b=%lld, c=%lld\n", b, c);

  ll v[3];
  v[0] = a, v[1] = b, v[2] = c;
  sort(v, v + 3);

  printf("%lld %lld %lld\n", v[0], v[1], v[2]);
  return 0;
}
0