結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー le_panda_noirle_panda_noir
提出日時 2020-06-20 21:25:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,266 bytes
コンパイル時間 941 ms
コンパイル使用メモリ 88,148 KB
実行使用メモリ 389,484 KB
最終ジャッジ日時 2023-09-16 17:46:32
合計ジャッジ時間 4,655 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
8,756 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 MLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
権限があれば一括ダウンロードができます

ソースコード

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