結果
問題 |
No.550 夏休みの思い出(1)
|
ユーザー |
![]() |
提出日時 | 2017-07-28 23:00:37 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,928 bytes |
コンパイル時間 | 1,377 ms |
コンパイル使用メモリ | 162,752 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-10-10 04:35:58 |
合計ジャッジ時間 | 5,981 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 50 WA * 5 |
ソースコード
#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; if(abs(a)<1e5&&abs(b)<1e5&&abs(c)<1e5){ bool flg=0; for(int i=-1e8;i<1e8;i++){ if(calc(i)==0){ if(flg) cout<<" "; cout<<i,flg=1; } } cout<<endl; return 0; } Int P=(A-sqrt(A*A-3*B))/3,Q=(A+sqrt(A*A-3*B))/3; //cout<<A*A-3*B<<" "<<sqrt(A*A-3*B)<<":"<<sqrt(A*A-3*B)*sqrt(A*A-3*B)<<endl; //cout<<P<<" "<<Q<<endl; //cout<<calc(P)<<" "<<calc(Q)<<endl; //cout<<calc(-114514)<<endl; { Int L=INT_MIN,R=-Q; //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=-Q,R=-P; //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; //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; }