結果

問題 No.2506 Sum of Weighted Powers
ユーザー suisensuisen
提出日時 2023-03-22 01:52:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 202 ms / 2,000 ms
コード長 1,755 bytes
コンパイル時間 2,232 ms
コンパイル使用メモリ 117,064 KB
実行使用メモリ 11,860 KB
最終ジャッジ日時 2023-10-13 18:22:42
合計ジャッジ時間 6,785 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,356 KB
testcase_06 AC 3 ms
4,352 KB
testcase_07 AC 2 ms
4,352 KB
testcase_08 AC 3 ms
4,352 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 3 ms
4,348 KB
testcase_11 AC 3 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 2 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,352 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 3 ms
4,348 KB
testcase_22 AC 2 ms
4,352 KB
testcase_23 AC 123 ms
8,224 KB
testcase_24 AC 161 ms
10,688 KB
testcase_25 AC 53 ms
5,236 KB
testcase_26 AC 176 ms
11,144 KB
testcase_27 AC 18 ms
4,352 KB
testcase_28 AC 202 ms
11,672 KB
testcase_29 AC 202 ms
11,860 KB
testcase_30 AC 202 ms
11,788 KB
testcase_31 AC 201 ms
11,732 KB
testcase_32 AC 201 ms
11,788 KB
testcase_33 AC 2 ms
4,352 KB
testcase_34 AC 2 ms
4,352 KB
testcase_35 AC 45 ms
4,552 KB
testcase_36 AC 52 ms
5,028 KB
testcase_37 AC 1 ms
4,348 KB
testcase_38 AC 1 ms
4,348 KB
testcase_39 AC 2 ms
4,352 KB
testcase_40 AC 1 ms
4,352 KB
testcase_41 AC 1 ms
4,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

#include <atcoder/modint>

using mint = atcoder::static_modint<943718401>;

namespace atcoder {
    std::istream& operator>>(std::istream& in, mint &a) {
        long long e; in >> e; a = e;
        return in;
    }
    
    std::ostream& operator<<(std::ostream& out, const mint &a) {
        out << a.val();
        return out;
    }
} // namespace atcoder

#include <atcoder/convolution>

mint solve(const int n, const mint x, const std::vector<mint> &a, const std::vector<mint> &b, const std::vector<mint> &c) {
    if (x == 0) {
        mint ans = 0;
        for (int i = 0; i <= n; ++i) {
            ans += a[i] * b[i] * c[0];
        }
        for (int i = 1; i <= n; ++i) {
            ans += a[i] * b[0] * c[i];
        }
        return ans;
    }

    auto t = [&](long long k) {
        return (k - 1) * k * (k + 1) / 3;
    };
    const mint inv_x = x.inv();

    std::vector<mint> f(n + 1), g(n + 1);
    for (int i = 0; i <= n; ++i) {
        const mint pow_inv_x = inv_x.pow(t(i));
        f[i] = b[i] * pow_inv_x;
        g[i] = c[i] * pow_inv_x;
    }
    const std::vector<mint> h = atcoder::convolution(f, g);

    mint ans = 0;
    for (int i = 0; i <= n; ++i) {
        const mint pow_x = x.pow(t(i));
        ans += a[i] * pow_x * h[i];
    }
    return ans;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n, x;
    std::cin >> n >> x;
    
    std::vector<mint> a(n + 1), b(n + 1), c(n + 1);
    for (int i = 0, v; i <= n; ++i) std::cin >> v, a[i] = v;
    for (int i = 0, v; i <= n; ++i) std::cin >> v, b[i] = v;
    for (int i = 0, v; i <= n; ++i) std::cin >> v, c[i] = v;

    std::cout << solve(n, x, a, b, c).val() << std::endl;
    return 0;
}
0