結果

問題 No.1066 #いろいろな色 / Red and Blue and more various colors (Easy)
ユーザー hir355hir355
提出日時 2020-05-30 00:07:24
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,860 bytes
コンパイル時間 2,170 ms
コンパイル使用メモリ 196,728 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-24 02:47:59
合計ジャッジ時間 4,109 ms
ジャッジサーバーID
(参考情報)
judge1 / 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 49 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 116 ms
5,376 KB
testcase_11 AC 31 ms
5,376 KB
testcase_12 AC 25 ms
5,376 KB
testcase_13 AC 31 ms
5,376 KB
testcase_14 AC 33 ms
5,376 KB
testcase_15 AC 81 ms
5,376 KB
testcase_16 AC 17 ms
5,376 KB
testcase_17 AC 18 ms
5,376 KB
testcase_18 AC 74 ms
5,376 KB
testcase_19 AC 29 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 59 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 119 ms
5,376 KB
testcase_26 AC 118 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define INF_LL 100000000000000000LL
#define INF 200000000
#define MOD 998244353
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

ll dp[2][6001];

signed main() {
    int n, q;
    cin >> n >> q;
    vl a(n);
    rep(i, n) cin >> a[i];
    dp[0][0] = 1;
    rep(i, n) {
        if(i % 2 == 0) {
            memset(dp[1], 0, sizeof(dp[1]));
            rep(j, n) {
                dp[1][j + 1] += dp[0][j];
                dp[1][j] += (ll)dp[0][j] * (a[i] - 1);
                dp[1][j + 1] %= MOD;
                dp[1][j] %= MOD;
            }
        } else {
            memset(dp[0], 0, sizeof(dp[0]));
            rep(j, n) {
                dp[0][j + 1] += dp[1][j];
                dp[0][j] += (ll)dp[1][j] * (a[i] - 1);
                dp[0][j + 1] %= MOD;
                dp[0][j] %= MOD;
            }
        }
    }
    rep(i, q) {
        int b;
        cin >> b;
        cout << dp[n % 2][b] << endl;
    }
    return 0;
}
0