結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー 👑 CleyL
提出日時 2023-03-26 23:17:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 665 ms
コンパイル使用メモリ 72,544 KB
最終ジャッジ日時 2025-02-11 18:26:22
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using namespace std;

const long long MOD = 998244353;

long long dp[2][6010];

int main(){
  int n,q;cin>>n>>q;
  vector<int> A(n);
  for(int i = 0; n > i; i++){
    cin>>A[i];
  }
  dp[0][0] = 1;
  for(int i = 0; n > i; i++){
    for(int j = 0; n > j; j++){
      dp[1][j+1] = (dp[1][j+1]+dp[0][j])%MOD;
      dp[1][j] = (dp[1][j]+dp[0][j]*(A[i]-1))%MOD;
    }
    for(int j = 0; n >= j; j++){
      dp[0][j] = dp[1][j];
      dp[1][j] = 0;
    }
  }
  for(int i = 0; q > i; i++){
    int x;cin>>x;
    cout << dp[0][x] << endl;
  }
}
0