結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー milanis48663220milanis48663220
提出日時 2020-05-29 21:56:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 953 bytes
コンパイル時間 724 ms
コンパイル使用メモリ 83,280 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-23 21:59:08
合計ジャッジ時間 1,877 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 27 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 62 ms
6,944 KB
testcase_11 AC 16 ms
6,940 KB
testcase_12 AC 12 ms
6,940 KB
testcase_13 AC 16 ms
6,948 KB
testcase_14 AC 17 ms
6,944 KB
testcase_15 AC 42 ms
6,940 KB
testcase_16 AC 9 ms
6,940 KB
testcase_17 AC 9 ms
6,940 KB
testcase_18 AC 39 ms
6,944 KB
testcase_19 AC 15 ms
6,944 KB
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 31 ms
6,944 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 ms
6,944 KB
testcase_24 AC 2 ms
6,940 KB
testcase_25 AC 63 ms
6,944 KB
testcase_26 AC 64 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;
int N, Q;
ll A[10000], B[10000]; 

ll dp[2][6005];

void init(){
    dp[0][0] = 1;
    for(int i = 1; i <= N; i++){
        for(int j = 0; j <= N; j++){
            dp[i%2][j] = 0;
        }
        for(int j = 0; j <= i-1; j++){
            // 1
            dp[i%2][(j+1)] += dp[(i-1)%2][j];
            dp[i%2][(j+1)] %= MOD;
            // 1 以外
            dp[i%2][j] += dp[(i-1)%2][j]*(A[i-1]-1);
            dp[i%2][j] %= MOD;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> Q;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < Q; i++) cin >> B[i];
    init();
    
    for(int i = 0; i < Q; i++){
        cout << dp[N%2][B[i]] << endl;
    }
}
0