結果

問題 No.1068 #いろいろな色 / Red and Blue and more various colors (Hard)
ユーザー 0w10w1
提出日時 2020-12-30 02:33:19
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,916 bytes
コンパイル時間 2,554 ms
コンパイル使用メモリ 207,232 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-04-16 00:59:54
合計ジャッジ時間 56,797 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
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 sz = 1 << 32 - __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) {
      cout << dq.size() << endl;
      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