結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー simkarensimkaren
提出日時 2020-05-30 15:26:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 2,186 ms
コンパイル使用メモリ 180,096 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 07:41:11
合計ジャッジ時間 4,170 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 69 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 175 ms
5,376 KB
testcase_11 AC 40 ms
5,376 KB
testcase_12 AC 31 ms
5,376 KB
testcase_13 AC 42 ms
5,376 KB
testcase_14 AC 45 ms
5,376 KB
testcase_15 AC 118 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 23 ms
5,376 KB
testcase_18 AC 105 ms
5,376 KB
testcase_19 AC 38 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 85 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 178 ms
5,376 KB
testcase_26 AC 178 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

constexpr ll mod = 998244353LL;

int main(void){
    int N, Q; cin >> N >> Q;
    vector<int> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    vector<vector<int>> DP(2, vector<int>(N + 1, 0));
    DP[0][0] = 1;
    for (int i = 0; i < N; ++i){
        for (int j = 0; j <= N; ++j)
            DP[(i + 1) & 1][j] = 0;
        for (int j = 0; j < N; ++j){
            DP[(i + 1) & 1][j] = (DP[(i + 1) & 1][j] + (int)(DP[i & 1][j] * (A[i] - 1LL) % mod)) % mod;
            DP[(i + 1) & 1][j + 1] = (DP[(i + 1) & 1][j + 1] + DP[i & 1][j]) % mod;
        }
    }
    while (Q--){
        int B; cin >> B;
        cout << DP[N & 1][B] << endl;
    }
    return 0;
}
0