結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー tomatoma
提出日時 2020-05-29 21:58:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,734 bytes
コンパイル時間 1,694 ms
コンパイル使用メモリ 171,588 KB
実行使用メモリ 285,040 KB
最終ジャッジ日時 2023-08-06 01:46:14
合計ジャッジ時間 5,295 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 161 ms
105,012 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 MLE -
testcase_11 AC 91 ms
60,004 KB
testcase_12 AC 69 ms
45,752 KB
testcase_13 AC 93 ms
61,972 KB
testcase_14 AC 100 ms
65,140 KB
testcase_15 MLE -
testcase_16 AC 42 ms
27,576 KB
testcase_17 AC 48 ms
32,068 KB
testcase_18 MLE -
testcase_19 AC 89 ms
57,624 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 192 ms
127,904 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 MLE -
testcase_26 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}

struct ModInt {
    static const ll MOD = 998244353;

    // constructors etc
    ModInt() :num(1ll) {}
    ModInt(ll num_) :num(num_%MOD) {}
    ModInt(const ModInt& modint) :num(modint.num%MOD) {}
    ll get()const { return num; }

    // operator etc
    // operator ll() const { return num; }
    // ll operator*() { return num; }
    ModInt& operator+=(const ModInt& r) { (num += r.num) %= MOD; return *this; }
    ModInt& operator-=(const ModInt& r) { (num += -r.num + MOD) %= MOD; return *this; }
    ModInt& operator*=(const ModInt& r) { (num *= r.num) %= MOD; return *this; }
    ModInt& operator/=(const ModInt& r) { (num *= r.inv().num) %= MOD; return *this; }
    ModInt pow(const ModInt& r)const {
        ll res = 1;
        ll x = num;
        ll n = r.num;
        while (n > 0) {
            if (n & 1)res = (res*x) % MOD;
            x = (x*x) % MOD;
            n >>= 1;
        }
        return res;
    }
    ModInt inv()const { return this->pow(MOD - 2); }

    ModInt operator+(const ModInt& r)const { return ModInt(*this) += r; }
    ModInt operator-(const ModInt& r)const { return ModInt(*this) -= r; }
    ModInt operator*(const ModInt& r)const { return ModInt(*this) *= r; }
    ModInt operator/(const ModInt& r)const { return ModInt(*this) /= r; }
    ModInt operator+(const ll& r)const { return *this + ModInt(r); }
    ModInt operator-(const ll& r)const { return *this - ModInt(r); }
    ModInt operator*(const ll& r)const { return *this * ModInt(r); }
    ModInt operator/(const ll& r)const { return *this / ModInt(r); }

private:
    ll num;
};
ostream& operator<<(ostream& stream, const ModInt& val) { stream << val.get(); return stream; }

// ============ template finished ============

int main()
{
    int N, Q;
    cin >> N >> Q;
    vector<int> A(N), B(Q);
    rep(i, N)cin >> A[i];
    rep(i, Q)cin >> B[i];
    vector<vector<ModInt>> dp(N, vector<ModInt>(N + 1, ModInt(0)));
    dp[0][0] = A[0] - 1;
    dp[0][1] = 1;
    REP(i, 1, N) {
        dp[i][0] = dp[i - 1][0] * (A[i] - 1);
        REP(j, 1, N + 1) {
            dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j] * (A[i] - 1);
        }
    }
    for (auto b : B) {
        cout << dp.back()[b] << endl;
    }
    return 0;
}
0