結果

問題 No.550 夏休みの思い出(1)
ユーザー kopricky
提出日時 2017-07-29 03:32:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 2,880 bytes
コンパイル時間 1,709 ms
コンパイル使用メモリ 171,128 KB
実行使用メモリ 13,696 KB
最終ジャッジ日時 2024-10-10 20:42:17
合計ジャッジ時間 8,174 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-12
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout <<" "<<kbrni;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

double na,nb,nc;
map<int,int> mp;

int eq(double kai)
{
    double res = kai*(kai*(kai+na)+nb)+nc;
    if(abs(res) < EPS){
        return 0;
    }else if(res > 0){
        return 1;
    }else{
        return 2;
    }
}

int eq2(double kai)
{
    double res = kai*(kai*(kai+na)+nb)+nc;
    if(abs(res) < EPS){
        return 0;
    }else if(res < 0){
        return 1;
    }else{
        return 2;
    }
}

ll aida(ll a,ll b)
{
    if(a >= 0){
        return (a+b)/2;
    }else{
        b += (-a);
        ll bf = a;
        a = 0;
        return (a+b)/2+bf;
    }
}

int main()
{
    ll a,b,c;
    cin >> a >> b >> c;
    na = a,nb = b,nc = c;
    double x = (-na-sqrt(na*na-3*nb))/3.0;
    double y = (-na+sqrt(na*na-3*nb))/3.0;
    ll h = (ll)(x-0.5);
    ll l = -(ll)pow(10,9);
    vector<int> ans;
    if(eq(h) == 0){
        ans.pb(h);
        mp[h]++;
    }else{
        while(1){
            ll mid = aida(l,h);
            int res = eq(mid);
            if(res == 0){
                ans.pb(mid);
                mp[mid]++;
                break;
            }else if(res == 1){
                h = mid;
            }else{
                l = mid;
            }
        }
    }
    h = (ll)(y-0.5);
    l = (ll)(x+0.5);
    if(eq2(l) == 0 && mp[l] == 0){
        ans.pb(l);
        mp[l]++;
    }else if(eq2(h) == 0 && mp[h] == 0){
        ans.pb(h);
        mp[h]++;
    }else{
        while(1){
            ll mid = aida(l,h);
            int res = eq2(mid);
            if(res == 0){
                ans.pb(mid);
                break;
            }else if(res == 1){
                h = mid;
            }else{
                l = mid;
            }
        }
    }
    h = (ll)pow(10,9);
    l = (ll)(y+0.5);
    ll hoge = (ll)(y-0.5);
    if(eq(hoge) == 0 && mp[hoge] == 0){
        ans.pb(hoge);
    }else if(eq(l) == 0 && mp[l] == 0){
        ans.pb(l);
    }else{
        while(1){
            ll mid = aida(l,h);
            int res = eq(mid);
            if(res == 0){
                ans.pb(mid);
                break;
            }else if(res == 1){
                h = mid;
            }else{
                l = mid;
            }
        }
    }
    sort(all(ans));
    cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
    return 0;
}
0