結果

問題 No.550 夏休みの思い出(1)
ユーザー beet
提出日時 2017-07-28 23:09:05
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 1,864 bytes
コンパイル時間 1,333 ms
コンパイル使用メモリ 165,592 KB
実行使用メモリ 16,840 KB
最終ジャッジ日時 2024-10-10 04:44:24
合計ジャッジ時間 7,764 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other TLE * 1 -- * 54
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
std::ostream &operator<<(std::ostream &dest, __int128_t value) {
  std::ostream::sentry s(dest);
  if (s) {
    __uint128_t tmp = value < 0 ? -value : value;
    char buffer[128];
    char *d = std::end(buffer);
    do {
      --d;
      *d = "0123456789"[tmp % 10];
      tmp /= 10;
    } while (tmp != 0);
    if (value < 0) {
      --d;
      *d = '-';
    }
    int len = std::end(buffer) - d;
    if (dest.rdbuf()->sputn(d, len) != len) {
      dest.setstate(std::ios_base::badbit);
    }
  }
  return dest;
}
using Int = __int128;
Int sqrt(Int A){
  Int L = 0, R = LLONG_MAX;
  while(L+1<R){
    Int M=(L+R)/2;
    if(M*M<=A) L=M;
    else R=M;
  }
  return L;
}
int a,b,c;
Int A,B,C;
Int calc(Int x){
  return x*x*x+A*x*x+B*x+C;
}
signed main(){
  cin>>a>>b>>c;
  A=a;B=b;C=c;
  Int P=(A-sqrt(A*A-3*B))/3,Q=(A+sqrt(A*A-3*B))/3;
  {
    Int L=INT_MIN,R=-Q;
    while(calc(L-1)>calc(L)) L--;
    while(calc(R)>calc(R+1)) R++;
    while(calc(L)>calc(L+1)) L++;
    while(calc(R-1)>calc(R)) R--;
    while(L+1<R){
      Int M=(L+R)/2;
      //cout<<M<<":"<<calc(M)<<endl;
      if(calc(M)<=0) L=M;
      else R=M;
    }
    cout<<L<<" ";
  }
  {
    Int L=-Q-100,R=-P+100;
    while(calc(L)<calc(L+1)) L++;
    while(calc(R-1)<calc(R)) R--;
    //cout<<calc(L)<<" "<<calc(R)<<endl;
    while(L+1<R){
      Int M=(L+R)/2;
      //cout<<M<<":"<<calc(M)<<endl;
      if(calc(M)>=0) L=M;
      else R=M;
    }
    cout<<L<<" ";
  }
  {
    Int L=-P,R=INT_MAX;
    while(calc(L-1)>calc(L)) L--;
    while(calc(R)>calc(R+1)) R++;
    while(calc(L)>calc(L+1)) L++;
    while(calc(R-1)>calc(R)) R--;
    //cout<<calc(L)<<" "<<calc(R)<<endl;
    while(L+1<R){
      Int M=(L+R)/2;
      //cout<<M<<":"<<calc(M)<<endl;
      if(calc(M)<=0) L=M;
      else R=M;
    }
    cout<<L<<endl;
  }
  return 0;
}
0