結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー kakel-san
提出日時 2025-10-17 21:59:22
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 745 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 198,524 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-17 21:59:26
合計ジャッジ時間 4,094 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n, 0);
    vector<int> b(q, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < q; i++) {
        cin >> b[i];
    }
    int mod = 998244353;
    vector<long> dp(n + 1, 0);
    vector<long> ndp(n + 1, 0);
    dp[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            ndp[j] = 0;
        }
        for (int j = 0; j < n; j++) {
            ndp[j] = (ndp[j] + dp[j] * (a[i] - 1) % mod) % mod;
            ndp[j + 1] = (ndp[j + 1] + dp[j]) % mod;
        }
        swap(dp, ndp);
    }
    for (int i = 0; i < q; i++) {
        cout << dp[b[i]] << endl;
    }
}
0