結果
問題 | No.1501 酔歩 |
ユーザー | noshi91 |
提出日時 | 2021-05-07 22:27:23 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,471 bytes |
コンパイル時間 | 1,107 ms |
コンパイル使用メモリ | 87,232 KB |
実行使用メモリ | 16,640 KB |
最終ジャッジ日時 | 2024-09-15 10:30:53 |
合計ジャッジ時間 | 6,041 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
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 | AC | 2 ms
5,376 KB |
testcase_14 | AC | 2 ms
5,376 KB |
testcase_15 | AC | 2 ms
5,376 KB |
testcase_16 | AC | 2 ms
5,376 KB |
testcase_17 | AC | 2 ms
5,376 KB |
testcase_18 | AC | 2 ms
5,376 KB |
testcase_19 | AC | 2 ms
5,376 KB |
testcase_20 | AC | 2 ms
5,376 KB |
testcase_21 | AC | 2 ms
5,376 KB |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | WA | - |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | AC | 64 ms
16,000 KB |
testcase_43 | AC | 2 ms
5,376 KB |
testcase_44 | AC | 2 ms
5,376 KB |
testcase_45 | AC | 61 ms
13,440 KB |
testcase_46 | AC | 62 ms
14,928 KB |
testcase_47 | AC | 62 ms
16,384 KB |
testcase_48 | AC | 79 ms
15,232 KB |
testcase_49 | AC | 79 ms
14,672 KB |
testcase_50 | AC | 78 ms
15,232 KB |
testcase_51 | WA | - |
testcase_52 | AC | 78 ms
15,488 KB |
testcase_53 | AC | 2 ms
5,376 KB |
testcase_54 | AC | 2 ms
5,376 KB |
testcase_55 | AC | 2 ms
5,376 KB |
ソースコード
#include <array> #include <cstdint> #include <iostream> #include <numeric> #include <queue> using u64 = std::uint64_t; struct rational { u64 num; u64 den; rational() : num(0), den(1) {} rational(u64 n, u64 d) : num(n), den(d) { u64 g = std::gcd(n, d); num /= g; den /= g; } friend rational operator+(const rational &l, const rational &r) { return {l.num * r.den + r.num * l.den, l.den * r.den}; } friend rational operator-(const rational &l, const rational &r) { return {l.num * r.den - r.num * l.den, l.den * r.den}; } friend rational operator*(const rational &l, const rational &r) { return {l.num * r.num, l.den * r.den}; } friend rational operator/(const rational &l, const rational &r) { return {l.num * r.den, l.den * r.num}; } }; using gate = std::array<std::array<rational, 2>, 2>; gate concat(const gate &l, const gate &r) { gate res = {}; res[0][1] = (rational(1, 1) - l[0][0]) * r[0][1] / (r[0][0] * l[1][0] + r[0][1]); res[0][0] = rational(1, 1) - res[0][1]; res[1][0] = (rational(1, 1) - r[1][1]) * l[1][0] / (l[1][1] * r[0][1] + l[1][0]); res[1][1] = rational(1, 1) - res[1][0]; return res; } int main() { int n, k; std::cin >> n >> k; if (n == k) { std::cout << "1/1\n"; return 0; } if (k == 1) { std::cout << "0\n"; return 0; } k -= 2; std::vector<int> a(n); for (auto &e : a) { std::cin >> e; } std::vector<gate> g(n - 2); for (int i = 0; i != n - 2; i += 1) { g[i][0][0] = g[i][1][0] = rational(a[i], a[i] + a[i + 2]); g[i][0][1] = g[i][1][1] = rational(a[i + 2], a[i] + a[i + 2]); } const auto aggregate = [&](const int l, const int r) { std::queue<gate> que; { gate t; t[0][0] = t[1][1] = rational(0, 1); t[0][1] = t[1][0] = rational(1, 1); que.push(t); } for (int i = l; i != r; i += 1) { que.push(g[i]); } while (que.size() != 1) { std::queue<gate> next; while (que.size() >= 2) { gate x = que.front(); que.pop(); gate y = que.front(); que.pop(); next.push(concat(x, y)); } if (!que.empty()) { next.push(que.front()); } que = std::move(next); } return que.front(); }; gate l = aggregate(0, k); gate r = aggregate(k, n - 2); rational ans = r[0][1] / (r[0][1] + r[0][0] * l[1][0]); std::cout << ans.num << "/" << ans.den << "\n"; return 0; }