結果
問題 |
No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
|
ユーザー |
![]() |
提出日時 | 2020-05-31 00:02:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 179 ms / 2,000 ms |
コード長 | 729 bytes |
コンパイル時間 | 2,147 ms |
コンパイル使用メモリ | 199,356 KB |
最終ジャッジ日時 | 2025-01-10 19:44:03 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef pair<int,int> P; constexpr int INF = 2e9; constexpr ll mod = 998244353; int main() { int n, q; cin >> n >> q; vector<int> a(n); rep(i,n) cin >> a[i]; vector<vector<ll>> dp(2, vector<ll>(n + 1, 0)); dp[0][0] = 1; for (int i = 0; i < n; i++) { dp[(i + 1) & 1] = vector<ll>(n + 1, 0); for (int j = 0; j <= n; j++) { (dp[(i + 1) & 1][j] += (dp[i & 1][j] * (a[i] - 1)) % mod) %= mod; if (j < n) (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; }