結果

問題 No.2506 Sum of Weighted Powers
ユーザー 👑 emthrmemthrm
提出日時 2023-03-28 23:34:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 405 ms / 2,000 ms
コード長 2,144 bytes
コンパイル時間 2,586 ms
コンパイル使用メモリ 151,968 KB
実行使用メモリ 12,748 KB
最終ジャッジ日時 2023-10-13 18:22:57
合計ジャッジ時間 8,086 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 3 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 3 ms
4,348 KB
testcase_07 AC 3 ms
4,352 KB
testcase_08 AC 5 ms
4,352 KB
testcase_09 AC 3 ms
4,348 KB
testcase_10 AC 5 ms
4,352 KB
testcase_11 AC 4 ms
4,352 KB
testcase_12 AC 2 ms
4,352 KB
testcase_13 AC 3 ms
4,352 KB
testcase_14 AC 2 ms
4,352 KB
testcase_15 AC 2 ms
4,352 KB
testcase_16 AC 3 ms
4,352 KB
testcase_17 AC 3 ms
4,356 KB
testcase_18 AC 3 ms
4,352 KB
testcase_19 AC 2 ms
4,352 KB
testcase_20 AC 3 ms
4,348 KB
testcase_21 AC 4 ms
4,348 KB
testcase_22 AC 3 ms
4,352 KB
testcase_23 AC 251 ms
8,504 KB
testcase_24 AC 313 ms
11,168 KB
testcase_25 AC 106 ms
5,488 KB
testcase_26 AC 345 ms
11,764 KB
testcase_27 AC 34 ms
4,356 KB
testcase_28 AC 402 ms
12,584 KB
testcase_29 AC 402 ms
12,620 KB
testcase_30 AC 402 ms
12,636 KB
testcase_31 AC 405 ms
12,748 KB
testcase_32 AC 405 ms
12,620 KB
testcase_33 AC 1 ms
4,352 KB
testcase_34 AC 2 ms
4,348 KB
testcase_35 AC 141 ms
6,000 KB
testcase_36 AC 166 ms
6,452 KB
testcase_37 AC 2 ms
4,352 KB
testcase_38 AC 2 ms
4,352 KB
testcase_39 AC 1 ms
4,348 KB
testcase_40 AC 2 ms
4,352 KB
testcase_41 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0