結果
問題 | No.550 夏休みの思い出(1) |
ユーザー | ojisan_IT |
提出日時 | 2017-08-08 04:42:57 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,820 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,820 KB |
testcase_05 | AC | 2 ms
6,820 KB |
testcase_06 | AC | 2 ms
6,820 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 2 ms
6,816 KB |
testcase_09 | AC | 2 ms
6,820 KB |
testcase_10 | AC | 2 ms
6,816 KB |
testcase_11 | AC | 2 ms
6,820 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,816 KB |
testcase_14 | AC | 2 ms
6,820 KB |
testcase_15 | AC | 2 ms
6,820 KB |
testcase_16 | AC | 1 ms
6,820 KB |
testcase_17 | AC | 2 ms
6,820 KB |
testcase_18 | AC | 2 ms
6,816 KB |
testcase_19 | AC | 2 ms
6,820 KB |
testcase_20 | AC | 2 ms
6,820 KB |
testcase_21 | AC | 2 ms
6,816 KB |
testcase_22 | AC | 2 ms
6,820 KB |
testcase_23 | AC | 2 ms
6,820 KB |
testcase_24 | AC | 2 ms
6,820 KB |
testcase_25 | AC | 2 ms
6,820 KB |
testcase_26 | AC | 2 ms
6,816 KB |
testcase_27 | AC | 2 ms
6,816 KB |
testcase_28 | AC | 1 ms
6,820 KB |
testcase_29 | AC | 2 ms
6,820 KB |
testcase_30 | AC | 1 ms
6,816 KB |
testcase_31 | AC | 2 ms
6,816 KB |
testcase_32 | AC | 2 ms
6,816 KB |
testcase_33 | AC | 2 ms
6,816 KB |
testcase_34 | AC | 2 ms
6,820 KB |
testcase_35 | AC | 2 ms
6,820 KB |
testcase_36 | AC | 2 ms
6,820 KB |
testcase_37 | AC | 2 ms
6,816 KB |
testcase_38 | AC | 1 ms
6,820 KB |
testcase_39 | AC | 2 ms
6,816 KB |
testcase_40 | AC | 2 ms
6,816 KB |
testcase_41 | AC | 2 ms
6,820 KB |
testcase_42 | AC | 2 ms
6,820 KB |
testcase_43 | AC | 2 ms
6,816 KB |
testcase_44 | AC | 2 ms
6,816 KB |
testcase_45 | AC | 2 ms
6,816 KB |
testcase_46 | AC | 2 ms
6,816 KB |
testcase_47 | AC | 2 ms
6,820 KB |
testcase_48 | AC | 1 ms
6,816 KB |
testcase_49 | AC | 2 ms
6,820 KB |
testcase_50 | AC | 2 ms
6,820 KB |
testcase_51 | AC | 2 ms
6,816 KB |
testcase_52 | AC | 2 ms
6,820 KB |
testcase_53 | AC | 2 ms
6,820 KB |
testcase_54 | AC | 2 ms
6,816 KB |
testcase_55 | AC | 2 ms
6,820 KB |
testcase_56 | AC | 2 ms
6,820 KB |
testcase_57 | AC | 1 ms
6,820 KB |
ソースコード
#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; } }