結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー 0w10w1
提出日時 2020-12-30 02:41:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,574 ms / 3,500 ms
コード長 2,032 bytes
コンパイル時間 2,537 ms
コンパイル使用メモリ 207,968 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-04-16 01:00:48
合計ジャッジ時間 49,923 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 34 ms
5,376 KB
testcase_04 AC 26 ms
5,376 KB
testcase_05 AC 30 ms
5,376 KB
testcase_06 AC 21 ms
5,376 KB
testcase_07 AC 19 ms
5,376 KB
testcase_08 AC 28 ms
5,376 KB
testcase_09 AC 32 ms
5,376 KB
testcase_10 AC 13 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 11 ms
5,376 KB
testcase_13 AC 2,561 ms
15,872 KB
testcase_14 AC 2,568 ms
16,000 KB
testcase_15 AC 2,563 ms
16,000 KB
testcase_16 AC 2,564 ms
16,000 KB
testcase_17 AC 2,564 ms
16,000 KB
testcase_18 AC 2,558 ms
16,000 KB
testcase_19 AC 2,562 ms
16,000 KB
testcase_20 AC 2,562 ms
16,000 KB
testcase_21 AC 2,562 ms
16,000 KB
testcase_22 AC 2,566 ms
16,000 KB
testcase_23 AC 2,567 ms
16,000 KB
testcase_24 AC 2,563 ms
16,000 KB
testcase_25 AC 2,574 ms
16,000 KB
testcase_26 AC 2,566 ms
16,000 KB
testcase_27 AC 2,561 ms
16,000 KB
testcase_28 AC 2,360 ms
16,000 KB
testcase_29 AC 2,294 ms
16,000 KB
testcase_30 AC 2,300 ms
16,000 KB
testcase_31 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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 z = 0; {
    for (int i = 0; i < (int) a.size(); ++i) if (norm(a[i])) z = max(z, i);
    for (int i = 0; i < (int) b.size(); ++i) if (norm(b[i])) z = max(z, i);
  }
  int sz = 1 << 33 - __builtin_clz(z);
  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) {
      dq.push_back(polyMul<M, 3>(dq[0], dq[1]));
      dq.pop_front();
      dq.pop_front();
    }
  }

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

0