結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー risujirohrisujiroh
提出日時 2020-05-29 21:42:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,549 bytes
コンパイル時間 2,012 ms
コンパイル使用メモリ 196,868 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 20:53:34
合計ジャッジ時間 3,024 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 16 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 39 ms
5,376 KB
testcase_11 AC 9 ms
5,376 KB
testcase_12 AC 7 ms
5,376 KB
testcase_13 AC 10 ms
5,376 KB
testcase_14 AC 11 ms
5,376 KB
testcase_15 AC 26 ms
5,376 KB
testcase_16 AC 5 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 24 ms
5,376 KB
testcase_19 AC 10 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 19 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 42 ms
5,376 KB
testcase_26 AC 42 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T, class Op = multiplies<T>>
constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  static constexpr unsigned mod = M;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
};

using mint = modular<998244353>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<mint> dp(n + 1);
  dp[0] = 1;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    vector<mint> ndp(n + 1);
    for (int x = 0; x <= i; ++x) {
      ndp[x + 1] += dp[x];
      ndp[x] += dp[x] * (a - 1);
    }
    swap(dp, ndp);
  }
  while (q--) {
    int b;
    cin >> b;
    cout << dp[b].v << '\n';
  }
}
0