結果
問題 | No.2970 三次関数の絶対値 |
ユーザー | erbowl |
提出日時 | 2024-11-29 22:12:31 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 7,553 bytes |
コンパイル時間 | 3,067 ms |
コンパイル使用メモリ | 253,468 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-29 22:12:36 |
合計ジャッジ時間 | 4,571 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 2 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | WA | - |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | WA | - |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 2 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 2 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | WA | - |
testcase_18 | AC | 2 ms
5,248 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 2 ms
5,248 KB |
testcase_22 | WA | - |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | WA | - |
testcase_27 | AC | 2 ms
5,248 KB |
testcase_28 | WA | - |
testcase_29 | AC | 2 ms
5,248 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | AC | 2 ms
5,248 KB |
testcase_34 | WA | - |
testcase_35 | AC | 2 ms
5,248 KB |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
testcase_40 | WA | - |
testcase_41 | AC | 2 ms
5,248 KB |
testcase_42 | WA | - |
testcase_43 | AC | 1 ms
5,248 KB |
testcase_44 | WA | - |
testcase_45 | WA | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | AC | 2 ms
5,248 KB |
testcase_49 | WA | - |
ソースコード
typedef long long ll; typedef long double ld; #include <bits/stdc++.h> using namespace std; // Union-Find struct UnionFind { // core member vector<int> par; // constructor UnionFind() { } UnionFind(int n) : par(n, -1) { } void init(int n) { par.assign(n, -1); } // core methods int root(int x) { if (par[x] < 0) return x; else return par[x] = root(par[x]); } bool same(int x, int y) { return root(x) == root(y); } bool merge(int x, int y) { x = root(x), y = root(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); // merge technique par[x] += par[y]; par[y] = x; return true; } int size(int x) { return -par[root(x)]; } // get groups vector<vector<int>> groups() { vector<vector<int>> member(par.size()); for (int v = 0; v < (int)par.size(); ++v) { member[root(v)].push_back(v); } vector<vector<int>> res; for (int v = 0; v < (int)par.size(); ++v) { if (!member[v].empty()) res.push_back(member[v]); } return res; } // debug friend ostream& operator << (ostream &s, UnionFind uf) { const vector<vector<int>> &gs = uf.groups(); for (const vector<int> &g : gs) { s << "group: "; for (int v : g) s << v << " "; s << endl; } return s; } }; // modint template<int MOD> struct Fp { // inner value long long val; // constructor constexpr Fp() : val(0) { } constexpr Fp(long long v) : val(v % MOD) { if (val < 0) val += MOD; } // getter constexpr long long get() const { return val; } constexpr int get_mod() const { return MOD; } // comparison operators constexpr bool operator == (const Fp &r) const { return this->val == r.val; } constexpr bool operator != (const Fp &r) const { return this->val != r.val; } // arithmetic operators constexpr Fp& operator += (const Fp &r) { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -= (const Fp &r) { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp& operator *= (const Fp &r) { val = val * r.val % MOD; return *this; } constexpr Fp& operator /= (const Fp &r) { long long a = r.val, b = MOD, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b, swap(a, b); u -= t * v, swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr Fp operator + () const { return Fp(*this); } constexpr Fp operator - () const { return Fp(0) - Fp(*this); } constexpr Fp operator + (const Fp &r) const { return Fp(*this) += r; } constexpr Fp operator - (const Fp &r) const { return Fp(*this) -= r; } constexpr Fp operator * (const Fp &r) const { return Fp(*this) *= r; } constexpr Fp operator / (const Fp &r) const { return Fp(*this) /= r; } // other operators constexpr Fp& operator ++ () { ++val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp& operator -- () { if (val == 0) val += MOD; --val; return *this; } constexpr Fp operator ++ (int) { Fp res = *this; ++*this; return res; } constexpr Fp operator -- (int) { Fp res = *this; --*this; return res; } friend constexpr istream& operator >> (istream &is, Fp<MOD> &x) { is >> x.val; x.val %= MOD; if (x.val < 0) x.val += MOD; return is; } friend constexpr ostream& operator << (ostream &os, const Fp<MOD> &x) { return os << x.val; } // other functions constexpr Fp pow(long long n) const { Fp res(1), mul(*this); while (n > 0) { if (n & 1) res *= mul; mul *= mul; n >>= 1; } return res; } constexpr Fp inv() const { Fp res(1), div(*this); return res / div; } friend constexpr Fp<MOD> pow(const Fp<MOD> &r, long long n) { return r.pow(n); } friend constexpr Fp<MOD> inv(const Fp<MOD> &r) { return r.inv(); } }; struct Eratos { vector<int> primes; vector<bool> isprime; vector<int> mebius; vector<int> min_factor; Eratos(int MAX) : primes(), isprime(MAX+1, true), mebius(MAX+1, 1), min_factor(MAX+1, -1) { isprime[0] = isprime[1] = false; min_factor[0] = 0, min_factor[1] = 1; for (int i = 2; i <= MAX; ++i) { if (!isprime[i]) continue; primes.push_back(i); mebius[i] = -1; min_factor[i] = i; for (int j = i*2; j <= MAX; j += i) { isprime[j] = false; if ((j / i) % i == 0) mebius[j] = 0; else mebius[j] = -mebius[j]; if (min_factor[j] == -1) min_factor[j] = i; } } } // prime factorization vector<pair<int,int>> prime_factors(int n) { vector<pair<int,int> > res; while (n != 1) { int prime = min_factor[n]; int exp = 0; while (min_factor[n] == prime) { ++exp; n /= prime; } res.push_back(make_pair(prime, exp)); } return res; } // enumerate divisors vector<int> divisors(int n) { vector<int> res({1}); auto pf = prime_factors(n); for (auto p : pf) { int n = (int)res.size(); for (int i = 0; i < n; ++i) { int v = 1; for (int j = 0; j < p.second; ++j) { v *= p.first; res.push_back(res[i] * v); } } } return res; } }; signed main(){ vector<ld> c(4); for (int i = 0; i < 4; i++) { std::cin >> c[i]; } ld l,r; std::cin >> l>>r; if(c[3]==0){ if(c[2]==0){ if(c[1]==0){ std::cout << c[0] << std::endl; return 0; } ld x = -c[0]/c[1]; if(l<=x&&x<=r){ std::cout << 0 << std::endl; return 0; } std::cout << min(abs(c[0]+l*c[1]), abs(c[0]+r*c[1])) << std::endl; return 0; } ld x = -1*c[1]/(ld)2/(ld)c[2]; std::cout<<setprecision(20) << min({ abs(c[0]+l*c[1]+l*l*c[2]), abs(c[0]+r*c[1]+r*r*c[2]), abs(c[0]+x*c[1]+x*x*c[2]) }) << std::endl; return 0; }else{ ld ans = 1e18; ld x1 = (c[2]+sqrtl(c[2]*c[2]-4*c[3]*c[1]))/(ld)4/c[3]; ld x2 = (c[2]-sqrtl(c[2]*c[2]-4*c[3]*c[1]))/(ld)4/c[3]; ans = min(ans, abs(c[0]+l*c[1]+l*l*c[2]+l*l*l*c[3])); ans = min(ans, abs(c[0]+r*c[1]+r*r*c[2]+r*r*r*c[3])); if(l<=x1&&x1<=r){ ans = min(ans, abs(c[0]+x1*c[1]+x1*x1*c[2]+x1*x1*x1*c[3])); } if(l<=x2&&x2<=r){ ans = min(ans, abs(c[0]+x2*c[1]+x2*x2*c[2]+x2*x2*x2*c[3])); } std::cout<<setprecision(20) << ans << std::endl; } }