結果

問題 No.550 夏休みの思い出(1)
ユーザー face4
提出日時 2019-11-20 14:36:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 862 bytes
コンパイル時間 916 ms
コンパイル使用メモリ 80,440 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-06 11:55:04
合計ジャッジ時間 2,597 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;

void g(ll *x, vector<int> &ans){
    ll det = sqrt(x[1]*x[1]-4*x[0]*x[2]);
    ans.push_back((-x[1]+det)/x[0]/2);
    ans.push_back((-x[1]-det)/x[0]/2);
}

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    auto f = [=](ll x)->ll{
        return x*x*x+a*x*x+b*x+c;
    };
    vector<int> ans;
    for(int i = 0; i < 1e6; i++){
        if(f(i) == 0){
            ans.push_back(i);
            break;
        }
        if(f(-i)==0){
            ans.push_back(-i);
            break;
        }
    }
    
    // 組み立て除法
    ll x[3];
    x[0] = 1;
    x[1] = a+x[0]*ans[0];
    x[2] = b+x[1]*ans[0];

    g(x, ans);

    sort(ans.begin(), ans.end());
    for(int i = 0; i < 3; i++)  cout << ans[i] << " \n"[i==2];
    
    return 0;
}
0