結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー 0w10w1
提出日時 2020-12-30 02:29:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,937 bytes
コンパイル時間 2,553 ms
コンパイル使用メモリ 207,872 KB
実行使用メモリ 63,692 KB
最終ジャッジ日時 2024-04-16 00:58:54
合計ジャッジ時間 9,493 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
63,692 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<int M, int G>
void ntt(vector<int> &v, bool inv = false) {
  const int n = v.size();
  int lg = __builtin_ctz(n);
  assert(n == (1 << lg));
  
  for (int j = 1, i = 0; j < n - 1; ++j) {
    for (int k = n >> 1; k > (i^=k); k >>= 1) ;
    if (j < i) swap(v[i], v[j]);
  }

  auto ipow = [](int v, int p, int m) {
    int r = 1;
    for (int i = p; i; i >>= 1) {
      if (i & 1) r = (int64_t) r * v % m;
      v = (int64_t) v * v % m;
    }
    return r;
  };

  for (int m = 2; m <= n; m *= 2) {
    int wn = ipow(G, (M - 1) / m, M);
    if (inv) wn = ipow(wn, M - 2, M);
    for (int i = 0; i < n; i += m) {
      int w = 1;
      for (int j = i; j < i + m/2; ++j) {
        int x = v[j];
        int y = (int64_t) w * v[j + m/2] % M;
        v[j] = x + y;
        v[j + m/2] = x - y;
        if (v[j] >= M) v[j] -= M;
        if (v[j + m/2] < 0) v[j + m/2] += M;
        w = (int64_t) w * wn % M;
      }
    }
  }

  if (inv) {
    int rn = ipow(n, M - 2, M);
    for (int i = 0; i < n; ++i) v[i] = (int64_t) v[i] * rn % M;
  }
}

template<int M, int G>
vector<int> polyMul(vector<int> a, vector<int> b) {
  int sz = 1 << 33 - __builtin_clz(max(a.size(), b.size()));
  a.resize(sz);
  b.resize(sz);
  ntt<M, G>(a);
  ntt<M, G>(b);
  for (int i = 0; i < sz; ++i) a[i] = (int64_t) a[i] * b[i] % M;
  ntt<M, G>(a, 1);
  return a;
}

int main() {
  const int M = 998244353;

  int N, Q; { cin >> N >> Q; }

  vector<int64_t> A(N); { for (int i = 0; i < N; ++i) cin >> A[i]; }
  
  vector<int> B(Q); { for (int i = 0; i < Q; ++i) cin >> B[i]; }

  deque<vector<int>> dq; {
    for (int i = 0; i < N; ++i) dq.push_back({ (int) ((A[i] - 1) % M), 1 });
    while (dq.size() > 1) {
      auto a = dq[0];
      auto b = dq[1];
      dq.pop_front();
      dq.pop_front();
      auto c = polyMul<M, 3>(a, b);
      dq.push_back(c);
    }
  }

  for (int b : B) cout << dq[0][b] << "\n";
}

0