結果
| 問題 |
No.550 夏休みの思い出(1)
|
| コンテスト | |
| ユーザー |
ojisan_IT
|
| 提出日時 | 2017-08-08 04:42:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 5,885 bytes |
| コンパイル時間 | 1,980 ms |
| コンパイル使用メモリ | 179,800 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-11 22:57:43 |
| 合計ジャッジ時間 | 3,379 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 55 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;
#define DEB cout<<"!"<<endl
#define SHOW(a,b) cout<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cout<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
#define MAX 1000000005
const ll BigIntDig = 8; // BigIntDig*9-dig
const ll Base = 1000000000;
class BigInt{
public:
int Num[BigIntDig];
bool sign; // 0 is positive,1 is negative - number
int size; // how many using Num-Array
BigInt();
BigInt(ll);
BigInt(string);
void Setstr(string);
int Carry(int,int);
void Deb();
};
BigInt operator-(BigInt x){
x.sign ^= 1;
return x;
}
// you can use this func after setting "size"
void BigInt::Setstr(string str){
if(str[0] == '-'){sign = 1; str = str.substr(1);}
else sign = 0;
int m = str.size() % 9;
if(m == 0)
m = 9;
Num[size-1]=atoi(str.substr(0,m).c_str());
for(int i = size-2; i >= 0; i--)
Num[i] = std::atoi(str.substr((size-i-1)*9-(9-m),9).c_str());
}
ostream &operator<<(ostream &os, BigInt x) {
if(x.sign) os << '-';
os << x.Num[x.size-1];
for (int i = x.size-2; i >= 0; --i)
os << setw(9) << setfill('0') << x.Num[i];
return os;
}
BigInt::BigInt(){
memset(Num,0,sizeof(Num));
size = 1;
sign = 1;
}
BigInt::BigInt(string str){
memset(Num,0,sizeof(Num));
size = (str.size()-1)/9 + 1;
Setstr(str);
}
BigInt::BigInt(ll num){
memset(Num,0,sizeof(Num));
if(num < 0) sign = 1;
else sign = 0;
num = llabs(num);
Num[0] = num % Base;
Num[1] = num / Base;
if(Num[1] != 0)
size = 2;
else
size = 1;
}
bool operator < (BigInt x,BigInt y){
if(x.sign && y.sign) return ((-y)<(-x));
if(x.sign && y.sign == 0) return true;
if(x.sign == 0 && y.sign) return false;
if(x.size != y.size) return x.size < y.size;
for(int i=x.size-1; i >= 0; i--)
if(x.Num[i] != y.Num[i]) return x.Num[i] < y.Num[i];
return false; // x == y
}
bool operator > (BigInt x,BigInt y){return y<x;}
bool operator <= (BigInt x,BigInt y){return !(y<x);}
bool operator >= (BigInt x,BigInt y){return !(x<y);}
bool operator != (BigInt x,BigInt y){return x<y || y<x;}
bool operator == (BigInt x,BigInt y){return !(x<y)&& !(y<x);}
BigInt resize(BigInt x){
while(x.Num[x.size-1] == 0 && x.size != 1)
x.size--;
return x;
}
int BigInt::Carry(int nsize,int value){ // nsize:point of carrying, value: value of carrying
if(value == 0)return 0;
int index = nsize+1;
if(index >= size){
size = index+1;
Num[index] = value;
}else{
int sum = Num[index] + value;
if(sum >= Base){
Carry(index,sum/Base);
sum %= Base;
Num[index] = sum;
}else{
Num[index] = sum;
}
}
return 0;
}
BigInt operator-(BigInt x, BigInt y);
BigInt operator+(BigInt x, BigInt y) {
if(x.sign && y.sign) return (-(-x+(-y)));
if(x.sign && y.sign == 0) return (y-(-x));
if(x.sign == 0 && y.sign) return (x-(-y));
if (x.size < y.size) x.size = y.size;
for (int i = 0; i < y.size; ++i){
x.Num[i] += y.Num[i];
if(x.Num[i] >= Base){
x.Carry(i,x.Num[i]/Base);
x.Num[i] %= Base;
}
}
return x;
}
BigInt operator-(BigInt x, BigInt y) {
if(x.sign && y.sign) return (-y)-(-x);
if(x.sign == 0 && y.sign) return x+y;
if(x.sign && y.sign == 0) return x+(-y);
if (x < y) {swap(x,y); x.sign ^= 1;}
for (int i = 0; i < y.size; ++i){
x.Num[i] -= y.Num[i];
if(x.Num[i] < 0){
x.Carry(i,-1);
x.Num[i] += Base;
}
}
return resize(x);
}
BigInt operator*(BigInt x,BigInt y){
int ys=y.size,xs = x.size;
BigInt ret;ret.size = 1; ret.sign = (x.sign + y.sign)%2;
for (int i = 0; i < xs; ++i){
for(int j = 0; j < ys; ++j){
ll mul = (ll)x.Num[i] * y.Num[j];
ret.Carry(i+j,mul/Base);
ret.Carry(i+j-1,mul%Base);
}
}
return ret;
}
void BigInt::Deb(){
for(int i = 0;i < size;i++)
cout << Num[i] << " " << i << endl;
}
ll a,b,c;
ll s = 1.0;
bool func(ll x){
BigInt bx(x);
if(resize(BigInt(s)*bx*bx*bx+BigInt(a)*bx*bx+BigInt(b)*bx+BigInt(c)) > BigInt((ll)0))
return true;
else
return false;
}
bool check(ll x){
BigInt bx(x);
if(BigInt(s)*bx*bx*bx+BigInt(a)*bx*bx+BigInt(b)*bx+BigInt(c) == BigInt((ll)0))
return true;
else
return false;
}
int main(){
cin >> a >> b >> c;
double B1 = (1.*(-a) + sqrt(1.*a*a-3.0*b))/3.0;
double B2 = (1.*(-a) - sqrt(1.*a*a-3.0*b))/3.0;
set<ll> ans;
for(ll i = B1 - 10; i <= B1 + 10; i++)
if(check(i))
ans.insert(i);
for(ll i = B2 - 10; i <= B2 + 10; i++)
if(check(i))
ans.insert(i);
ll bottom = -1000000000;
ll top = B2;
while(llabs(top-bottom) > 1){
if(func((top+bottom)/2)) top = (top+bottom)/2;
else bottom = (top+bottom)/2;
}
for(ll i = bottom - 10; i <= bottom + 10; i++)
if(check(i))
ans.insert(i);
bottom = B1;
top = B2;
while(llabs(top-bottom) > 1){
if(func((top+bottom)/2)) top = (top+bottom)/2;
else bottom = (top+bottom)/2;
}
for(ll i = bottom - 10; i <= bottom + 10; i++)
if(check(i))
ans.insert(i);
bottom = B1;
top = 1000000000;
while(llabs(top-bottom) > 1){
if(func((top+bottom)/2)) top = (top+bottom)/2;
else bottom = (top+bottom)/2;
}
for(ll i = bottom - 10; i <= bottom + 10; i++)
if(check(i))
ans.insert(i);
for(auto itr = ans.begin(); itr != ans.end();itr++){
if(itr != ans.end())
cout << *itr << " ";
else
cout << *itr << endl;
}
}
ojisan_IT