結果
問題 | No.3054 ほぼ直角二等辺三角形 |
ユーザー | risujiroh |
提出日時 | 2019-04-06 08:27:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 5 ms / 2,000 ms |
コード長 | 5,069 bytes |
コンパイル時間 | 1,844 ms |
コンパイル使用メモリ | 183,952 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-23 13:58:51 |
合計ジャッジ時間 | 3,276 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,812 KB |
testcase_01 | AC | 5 ms
6,816 KB |
testcase_02 | AC | 5 ms
6,940 KB |
testcase_03 | AC | 5 ms
6,940 KB |
testcase_04 | AC | 5 ms
6,944 KB |
testcase_05 | AC | 5 ms
6,944 KB |
testcase_06 | AC | 5 ms
6,948 KB |
testcase_07 | AC | 5 ms
6,940 KB |
testcase_08 | AC | 5 ms
6,940 KB |
testcase_09 | AC | 5 ms
6,940 KB |
testcase_10 | AC | 5 ms
6,940 KB |
testcase_11 | AC | 5 ms
6,940 KB |
testcase_12 | AC | 5 ms
6,944 KB |
testcase_13 | AC | 5 ms
6,944 KB |
testcase_14 | AC | 5 ms
6,940 KB |
testcase_15 | AC | 5 ms
6,940 KB |
testcase_16 | AC | 5 ms
6,944 KB |
testcase_17 | AC | 5 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; using lint = long long; template<class T = int> using V = vector<T>; template<class T = int> using VV = V< V<T> >; template<unsigned P> struct ModInt { using M = ModInt; unsigned v; ModInt() : v(0) {} template<class Z> ModInt(Z x) : v(x >= 0 ? x % P : (P - -x % P) % P) {} constexpr ModInt(unsigned v, int) : v(v) {} static constexpr unsigned p() { return P; } M operator+() const { return *this; } M operator-() const { return {v ? P - v : 0, 0}; } explicit operator bool() const noexcept { return v; } bool operator!() const noexcept { return !(bool) *this; } M operator*(M r) const { return M(*this) *= r; } M operator/(M r) const { return M(*this) /= r; } M operator+(M r) const { return M(*this) += r; } M operator-(M r) const { return M(*this) -= r; } bool operator==(M r) const { return v == r.v; } bool operator!=(M r) const { return !(*this == r); } M& operator*=(M r) { v = (uint64_t) v * r.v % P; return *this; } M& operator/=(M r) { return *this *= r.inv(); } M& operator+=(M r) { if ((v += r.v) >= P) v -= P; return *this; } M& operator-=(M r) { if ((v += P - r.v) >= P) v -= P; return *this; } M inv() const { int a = v, b = P, x = 1, u = 0; while (b) { int q = a / b; swap(a -= q * b, b); swap(x -= q * u, u); } assert(a == 1); return x; } template<class Z> M pow(Z n) const { if (n < 0) return pow(-n).inv(); M res = 1; for (M a = *this; n; a *= a, n >>= 1) if (n & 1) res *= a; return res; } template<class Z> friend M operator*(Z l, M r) { return M(l) *= r; } template<class Z> friend M operator/(Z l, M r) { return M(l) /= r; } template<class Z> friend M operator+(Z l, M r) { return M(l) += r; } template<class Z> friend M operator-(Z l, M r) { return M(l) -= r; } friend ostream& operator<<(ostream& os, M r) { return os << r.v; } friend istream& operator>>(istream& is, M& r) { lint x; is >> x; r = x; return is; } template<class Z> friend bool operator==(Z l, M r) { return M(l) == r; } template<class Z> friend bool operator!=(Z l, M r) { return !(l == r); } }; using Mint = ModInt<(unsigned) 1e9 + 7>; lint powll(lint a, int n) { assert(n >= 0); lint res = 1; for (; n > 0; a *= a, n >>= 1) if (n & 1) res *= a; return res; } // Ax=b(A_{ij}=a_{i+j})をO(n^2)で解くかもしれない(は?) template<class T> V<T> levinson_durbin(const V<T>& a, const V<T>& b) { assert(a.size() == 2 * b.size() - 1); int n = b.size(); if (!a[n - 1]) return {}; V<T> p(n), q(n), x(n); p.back() = q[0] = 1 / a[n - 1]; x.back() = b[0] / a[n - 1]; for (int k = 1; k < n; ++k) { T ep = inner_product(begin(a) + n, begin(a) + n + k, begin(p) + n - k, (T) 0); T eq = inner_product(begin(a) + n - 1 - k, begin(a) + n - 1, begin(q), (T) 0); T e = inner_product(begin(a) + n, begin(a) + n + k, begin(x) + n - k, (T) 0); if (!(1 - ep * eq)) { for (int i = 0; i < n; ++i) { if (inner_product(begin(a) + i, begin(a) + i + n, begin(x), (T) 0) != b[i]) { return {}; } } return x; } T c = 1 / (1 - ep * eq); for (int i = 0; i <= k; ++i) { T tp = i ? p[n - 1 - k + i] : 0, tq = i < k ? q[i] : 0; tie(p[n - 1 - k + i], q[i]) = make_pair(c * (tp - ep * tq), c * (tq - eq * tp)); x[n - 1 - k + i] += (b[k] - e) * q[i]; } } return x; } // aが線形漸化的のとき係数をO(n^2)で復元するかもしれない(は?) template<class T> V<T> restore_coeff(const V<T>& a) { int k = a.size() >> 1; while (k) { auto c = levinson_durbin(V<T>(begin(a), begin(a) + 2 * k - 1), V<T>(begin(a) + k, begin(a) + 2 * k)); auto chk = [&]() -> bool { for (int i = 0; i + k < (int) a.size(); ++i) { if (inner_product(begin(c), end(c), begin(a) + i, (T) 0) != a[i + k]) { return false; } } return true; }; if (!c.empty() and chk()) { int i = 0; while (i < k and !c[i] and inner_product(begin(c) + i + 1, end(c), begin(a), (T) 0) == a[k - 1 - i]) ++i; return V<T>(begin(c) + i, end(c)); } --k; } return {}; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); // 1e6以下を愚直に列挙 V<Mint> ma; for (lint i = 1; i <= 1e6; ++i) { lint s = i * i + (i + 1) * (i + 1); lint sq = sqrt(s); if (sq * sq == s) ma.push_back(i); } // どうせ線形漸化式に従うので復元 auto mcoeff = restore_coeff(ma); assert(!mcoeff.empty()); int k = mcoeff.size(); V<lint> coeff(k), res(k); for (int i = 0; i < k; ++i) { coeff[i] = mcoeff[i].v; if (coeff[i] > 5e8) coeff[i] -= Mint::p(); res[i] = ma[i].v; } while (true) { lint nxt = inner_product(begin(coeff), end(coeff), end(res) - k, 0LL); if (nxt >= 1e18) break; res.push_back(nxt); } int x; cin >> x; lint a = *lower_bound(begin(res), end(res), powll(10, x - 1)); lint b = a + 1, c = sqrt(1.0L * a * a + 1.0L * b * b) + 0.5; cout << a << ' ' << b << ' ' << c << '\n'; }