結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー le_panda_noir
提出日時 2020-06-20 21:10:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
MLE  
実行時間 -
コード長 1,225 bytes
コンパイル時間 802 ms
コンパイル使用メモリ 66,816 KB
最終ジャッジ日時 2025-01-11 08:47:32
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 MLE * 1
other AC * 17 TLE * 2 MLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)

template<int MOD> struct MInt {
  long long val;
  constexpr MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
};
using mint = MInt<998244353>;

int N, Q;
int A[6000];
mint dp[6000][6000];
bool visited[6000][6000];
mint dfs(int i, int candidate) {
  if (N-i < candidate)
    return 0;
  if (i == N)
    return candidate == 0;
  if (visited[i][candidate])
    return dp[i][candidate];
  visited[i][candidate] = true;
  return dp[i][candidate] = dfs(i+1, candidate-1) + dfs(i+1, candidate) * (A[i]-1);
}
int main() {
  ins(N, Q);

  rep(i, N) {
    cin >> A[i];
  }
  rep(q, Q) {
    int B; cin >> B;
    cout << dfs(0, B) << endl;
  }

  return 0;
}
0