結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー veqccveqcc
提出日時 2020-05-29 22:33:00
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 2,610 bytes
コンパイル時間 1,083 ms
コンパイル使用メモリ 108,740 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-23 23:36:12
合計ジャッジ時間 2,790 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 46 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 112 ms
5,376 KB
testcase_11 AC 28 ms
5,376 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 29 ms
5,376 KB
testcase_14 AC 31 ms
5,376 KB
testcase_15 AC 76 ms
5,376 KB
testcase_16 AC 14 ms
5,376 KB
testcase_17 AC 16 ms
5,376 KB
testcase_18 AC 71 ms
5,376 KB
testcase_19 AC 28 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 55 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 116 ms
5,376 KB
testcase_26 AC 115 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 998244353;

template <ll mod> class ModInt {
    ll a;
public:
    constexpr ModInt(const ll a = 0) noexcept : a((a % mod + mod) % mod) {}
    constexpr ll &value() noexcept { return a; }
    constexpr ModInt operator + (const ModInt &rhs) const noexcept { return ModInt(*this) += rhs; }
    constexpr ModInt operator - (const ModInt &rhs) const noexcept { return ModInt(*this) -= rhs; }
    constexpr ModInt operator * (const ModInt &rhs) const noexcept { return ModInt(*this) *= rhs; }
    constexpr ModInt operator / (const ModInt &rhs) const noexcept { return ModInt(*this) /= rhs; }
    constexpr ModInt &operator += (const ModInt &rhs) noexcept {
        a += rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator -= (const ModInt &rhs) noexcept {
        a += mod - rhs.a;
        if (a >= mod) a -= mod;
        return *this;
    }
    constexpr ModInt &operator *= (const ModInt &rhs) noexcept {
        a = a * rhs.a % mod;
        return *this;
    }
    constexpr ModInt pow(ll t) const noexcept {
        if (t == 0) return 1;
        auto ret = pow(t >> 1);
        ret *= ret;
        if (t & 1) ret *= *this;
        return ret;
    }
    constexpr ModInt inv() const noexcept { return pow(mod - 2); }
    constexpr ModInt operator /=(const ModInt &rhs) { return (*this) *= rhs.inv(); }
    constexpr bool operator == (const ModInt &rhs) const noexcept { return this->a == rhs.a; }
    constexpr bool operator != (const ModInt &rhs) const noexcept { return this->a != rhs.a; }
    friend constexpr ostream &operator << (ostream &os, const ModInt &rhs) noexcept { return os << rhs.a; }
    friend constexpr istream &operator >> (istream &is, ModInt &rhs) {
        is >> rhs.a;
        return is;
    }
};
using mint = ModInt<MOD>;

int main() {
    int n, q;
    cin >> n >> q;

    vector<mint> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<vector<mint>> dp(2, vector<mint>(n + 1, 0));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= n; j++) {
            dp[1][j] = dp[0][j] * (a[i] - 1);
            if (j) dp[1][j] += dp[0][j - 1];
        }
        swap(dp[0], dp[1]);
    }

    while (q--) {
        int b;
        cin >> b;
        cout << dp[0][b] << endl;
    }

    return 0;
}
0