結果

問題 No.2506 Sum of Weighted Powers
ユーザー 👑 emthrm
提出日時 2023-03-28 23:34:35
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 428 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 2,742 ms
コンパイル使用メモリ 150,320 KB
実行使用メモリ 12,988 KB
最終ジャッジ日時 2024-09-15 14:12:02
合計ジャッジ時間 8,008 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>
#include <atcoder/convolution>
#include <atcoder/modint>
using mint = atcoder::static_modint<943718401>;
mint S(const int n, const mint& x,
std::vector<mint> a, std::vector<mint> b, std::vector<mint> c) {
assert(n == std::ssize(a) - 1 &&
n == std::ssize(b) - 1 &&
n == std::ssize(c) - 1);
// ijk \neq 0 A_i B_j C_k x^{ijk} = 0
// ijk = 0 \iff j = 0 k = 0
if (x == 0) {
mint s = 0;
// j = 0
s += std::inner_product(a.begin(), a.end(), b.begin(), mint::raw(0)) * c[0];
// j > 0 k = 0
s += std::inner_product(std::next(a.begin()), a.end(),
std::next(c.begin()), mint::raw(0)) * b[0];
return s;
}
const auto T = [](const int i) -> std::int64_t {
return std::int64_t{i - 1} * i * (i + 1) / 3;
};
// A_i x^{t_i}
std::ranges::for_each(
a, [&x, T, i = 0](mint& e) mutable -> void { e *= x.pow(T(i++)); });
// B_j / x^{t_j}, C_k / x^{t_k}
const mint inv = x.inv();
std::ranges::for_each(
b, [&inv, T, i = 0](mint& e) mutable -> void { e *= inv.pow(T(i++)); });
std::ranges::for_each(
c, [&inv, T, i = 0](mint& e) mutable -> void { e *= inv.pow(T(i++)); });
const std::vector<mint> s = atcoder::convolution(b, c);
return std::inner_product(a.begin(), a.end(), s.begin(), mint::raw(0));
}
int main() {
constexpr int kMaxN = 200000;
const auto GetMint = []() -> mint {
int x;
std::cin >> x;
assert(0 <= x && x < mint::mod());
return mint::raw(x);
};
int n;
std::cin >> n;
assert(0 <= n && n <= kMaxN);
const mint x = GetMint();
std::vector<mint> a(n + 1), b(n + 1), c(n + 1);
std::ranges::for_each(a, [GetMint](mint& x) -> void { x = GetMint(); });
std::ranges::for_each(b, [GetMint](mint& x) -> void { x = GetMint(); });
std::ranges::for_each(c, [GetMint](mint& x) -> void { x = GetMint(); });
std::cout << S(n, x, a, b, c).val() << '\n';
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0