結果
問題 | No.1066 #いろいろな色 / Red and Blue and more various colors (Easy) |
ユーザー |
![]() |
提出日時 | 2020-05-29 21:27:16 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 2,307 bytes |
コンパイル時間 | 2,830 ms |
コンパイル使用メモリ | 198,448 KB |
最終ジャッジ日時 | 2025-01-10 16:29:59 |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 21 MLE * 3 |
ソースコード
#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<vector<Mint>> dp(n, vector<Mint> (n + 1));dp[0][0] = a[0] - 1;dp[0][1] = 1;for (int i = 1; i < n; ++i){dp[i][0] = dp[i - 1][0] * (a[i] - 1);for (int j = 1; j <= n; ++j){dp[i][j] = dp[i - 1][j] * (a[i] - 1) + dp[i - 1][j - 1];}}for (int i = 0; i < q; ++i){int b;cin >> b;cout << dp[n - 1][b] << '\n';}return 0;}