結果
問題 | No.8054 ほぼ直角二等辺三角形 |
ユーザー | risujiroh |
提出日時 | 2019-04-06 08:14:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,983 bytes |
コンパイル時間 | 1,853 ms |
コンパイル使用メモリ | 179,852 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-06-23 13:15:54 |
合計ジャッジ時間 | 3,456 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 4 ms
6,816 KB |
testcase_01 | AC | 5 ms
6,944 KB |
testcase_02 | AC | 5 ms
6,944 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
ソースコード
#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> >;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<double> da;for (lint i = 1; i <= 1e6; ++i) {lint s = i * i + (i + 1) * (i + 1);lint sq = sqrt(s);if (sq * sq == s) da.push_back(i);}// どうせ線形漸化式に従うので復元auto dcoeff = restore_coeff(da);assert(!dcoeff.empty());int k = dcoeff.size();V<lint> coeff(k), res(k);for (int i = 0; i < k; ++i) {coeff[i] = dcoeff[i];res[i] = da[i];}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);cout << a << ' ' << b << ' ' << c << '\n';}