結果
| 問題 |
No.550 夏休みの思い出(1)
|
| ユーザー |
myanta
|
| 提出日時 | 2017-07-28 23:47:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 23 ms / 2,000 ms |
| コード長 | 1,204 bytes |
| コンパイル時間 | 450 ms |
| コンパイル使用メモリ | 43,648 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 05:33:16 |
| 合計ジャッジ時間 | 2,130 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
using vll=vector<ll>;
int sign(ll x)
{
if(x<0) return -1;
return x>0;
}
int solve2(vll&ans, ll d, ll e)
{
ll l, r, x;
int l_sign, x_sign;
l=-1000000000;
r=d/2;
x=l;
l_sign=sign(x*x-d*x+e);
if(l_sign==0)
{
if(e%l) return 0;
ans[1]=l;
ans[2]=e/l;
return 1;
}
for(;l<=r;)
{
x=(l+r)/2;
x_sign=sign(x*x-d*x+e);
if(x_sign==0)
{
if(e%x) return 0;
ans[1]=x;
ans[2]=e/x;
return 1;
}
if(x_sign==l_sign)
{
l=x+1;
}
else
{
r=x-1;
}
}
return 0;
}
void solve3(vll&ans, ll a, ll b, ll c)
{
if(c==0)
{
ans[0]=0;
solve2(ans, -a, b);
return;
}
for(ll i=1;i<=1000000;i++)
{
if(c%i) continue;
if((b+c/i)%i) continue;
ans[0]=i;
if(solve2(ans, (b+c/i)/i,-c/i)) return;
}
for(ll i=1;i<=1000000;i++)
{
if(c%i) continue;
if((b-c/i)%i) continue;
ans[0]=-i;
if(solve2(ans, -(b-c/i)/i, c/i)) return;
}
}
int main(void)
{
ll a, b, c;
while(scanf("%lld%lld%lld", &a, &b, &c)==3)
{
vll ans(3);
solve3(ans, a, b, c);
sort(ans.begin(), ans.end());
printf("%lld %lld %lld\n", ans[0], ans[1], ans[2]);
}
return 0;
}
myanta