結果

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
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];
vector<map<int, mint>> dp;
mint dfs(int i, int candidate) {
  if (i == N)
    return candidate == 0;
  if (N-i < candidate)
    return 0;
  if (candidate < 0)
    return 0;
  if (dp[i].count(candidate) > 0)
    return dp[i][candidate];
  return dp[i][candidate] = dfs(i+1, candidate-1) + dfs(i+1, candidate) * (A[i]-1);
}
int main() {
  ins(N, Q);

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

  return 0;
}

0