結果

問題 No.550 夏休みの思い出(1)
コンテスト
ユーザー milanis48663220
提出日時 2019-09-28 20:35:03
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 643 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 546 ms
コンパイル使用メモリ 78,832 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-19 06:10:36
合計ジャッジ時間 2,962 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34 WA * 21
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:26:5: warning: 'ans[0]' may be used uninitialized [-Wmaybe-uninitialized]
   26 |     if(ans[0] == 0){
      |     ^~
main.cpp:18:9: note: 'ans[0]' was declared here
   18 |     int ans[3];
      |         ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <cmath>

using namespace std;

typedef long long ll;

const int N = 1e6;

ll A, B, C;

ll calc(ll x){
    return x*x*x+A*x*x+B*x+C;
}

int main(){
    cin >> A >> B >> C;
    int ans[3];
    for(int i = -N; i <= N; i++){
        if(calc(i) == 0){
            ans[0] = i;
            break;
        }
    }
    ll b, c;
    if(ans[0] == 0){
        b = A;
        c = C;
    }else{
        b = A+ans[0];
        c = -C/ans[0];
    }
    ll sq = sqrt(b*b-4*c);
    if((sq+1)*(sq+1) == b*b-4*c) sq = sq+1;
    ans[1] = (-b-sq)/2;
    ans[2] = (-b+sq)/2;
    cout << ans[0] << ' ' << ans[1] << ' ' << ans[2] << endl;
}
0