結果

問題 No.2506 Sum of Weighted Powers
ユーザー 👑 emthrmemthrm
提出日時 2023-03-29 01:16:42
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,163 bytes
コンパイル時間 2,942 ms
コンパイル使用メモリ 160,152 KB
実行使用メモリ 14,504 KB
最終ジャッジ日時 2024-04-10 18:15:14
合計ジャッジ時間 6,451 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 4 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 3 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 3 ms
5,376 KB
testcase_23 AC 162 ms
9,904 KB
testcase_24 AC 207 ms
13,016 KB
testcase_25 AC 73 ms
6,508 KB
testcase_26 AC 224 ms
13,272 KB
testcase_27 AC 27 ms
5,376 KB
testcase_28 AC 260 ms
14,504 KB
testcase_29 AC 259 ms
14,504 KB
testcase_30 AC 260 ms
14,312 KB
testcase_31 AC 258 ms
14,376 KB
testcase_32 AC 256 ms
14,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 2 ms
5,376 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 2 ms
5,376 KB
testcase_39 AC 2 ms
5,376 KB
testcase_40 AC 2 ms
5,376 KB
testcase_41 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <iterator>
#include <numeric>
#include <vector>

#include <atcoder/convolution>
#include <atcoder/modint>

using mint = atcoder::static_modint<943718401>;

// <嘘解法 (WA)>
// x = 0 のとき S = \sum_{i = 0}^n (A_i B_i C_0 + A_i B_0 C_i) と計算している。
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);

  if (x == 0) {
    mint s = 0;
    s += std::inner_product(a.begin(), a.end(), b.begin(), mint::raw(0)) * c[0];
    s += std::inner_product(a.begin(), a.end(), c.begin(), mint::raw(0)) * b[0];
    return s;
  }

  const auto MakeWeights = [n](mint base) -> std::vector<mint> {
    base *= base;
    mint single_exp = 1, double_exp = 1;
    std::vector<mint> weights(n + 1, 1);
    for (int i = 0; i < n; ++i) {
      double_exp *= single_exp;
      single_exp *= base;
      weights[i + 1] = weights[i] * double_exp;
    }
    return weights;
  };

  std::ranges::transform(a, MakeWeights(x), a.begin(), std::multiplies<mint>());
  const std::vector<mint> weights_inv = MakeWeights(x.inv());
  std::ranges::transform(b, weights_inv, b.begin(), std::multiplies<mint>());
  std::ranges::transform(c, weights_inv, c.begin(), std::multiplies<mint>());

  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