結果

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

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
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)
#define rrep(i,n) for(long long i=(n);i>=0;--i)

int N, Q;
int A[6000];
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; }
};
constexpr int MOD = 998244353;
using mint = MInt<MOD>;
int main() {
  ins(N, Q);

  vector<mint> dp(N+1);
  rep(i, N) {
    cin >> A[i];
  }
  dp[0] = 1; dp[1] = 0;
  rrep(i, N-1) {
    vector<mint> dp_next(N+1);
    rep(j, N+1-i) {
      dp_next[j] = dp[j] * (A[i]-1);
      if (j >= 1) {
        dp_next[j] = dp[j-1] + dp_next[j];
      }
    }
    swap(dp, dp_next);
  }

  rep(q, Q) {
    int B; cin >> B;
    cout << dp[B] << endl;
  }

  return 0;
}

0