結果
問題 | No.1066 #いろいろな色 / Red and Blue and more various colors (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 21:29:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 158 ms / 2,000 ms |
コード長 | 2,290 bytes |
コンパイル時間 | 2,314 ms |
コンパイル使用メモリ | 196,104 KB |
最終ジャッジ日時 | 2025-01-10 16:32:07 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 24 |
ソースコード
#include <bits/stdc++.h>using namespace std;const int mod = 998244353;template<int mod>class ModInt {int x;public:ModInt() : x(0) {}ModInt(long long int y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}ModInt &operator+=(const ModInt& p){if ((x += p.x) >= mod){x -= mod;}return *this;}ModInt &operator-=(const ModInt& p){if ((x += mod - p.x) >= mod){x -= mod;}return *this;}ModInt &operator*=(const ModInt& p){x = (int) (1LL * x * p.x % mod);return *this;}ModInt &operator/=(const ModInt& p){*this *= p.Inverse();return *this;}ModInt operator-() const{return ModInt(-x);}ModInt operator+(const ModInt& p){return ModInt(*this) += p;}ModInt operator-(const ModInt& p){return ModInt(*this) -= p;}ModInt operator*(const ModInt& p){return ModInt(*this) *= p;}ModInt operator/(const ModInt& p){return ModInt(*this) /= p;}bool operator==(const ModInt& p){return x == p.x;}bool operator!=(const ModInt& p){return x!= p.x;}ModInt Inverse() const{int a = x, m = mod, u = 1, v = 0, t;while (m > 0){t = a / m;swap(a -= t * m, m);swap(u -= t * v, v);}return ModInt(u);}friend ostream &operator<<(ostream &os, const ModInt& p){return os << p.x;}};using Mint = ModInt<mod>;int main(){ios::sync_with_stdio(false);cin.tie(nullptr);int n, q;cin >> n >> q;vector<int> a(n);for (int i = 0; i < n; ++i){cin >> a[i];}vector<Mint> dp(n + 1), new_dp(n + 1);dp[0] = a[0] - 1;dp[1] = 1;for (int i = 1; i < n; ++i){new_dp[0] = dp[0] * (a[i] - 1);for (int j = 1; j <= n; ++j){new_dp[j] = dp[j - 1] + dp[j] * (a[i] - 1);}swap(dp, new_dp);}for (int i = 0; i < q; ++i){int b;cin >> b;cout << dp[b] << '\n';}return 0;}