結果

問題 No.1239 Multiplication -2
ユーザー trineutrontrineutron
提出日時 2020-09-25 22:48:51
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 2,138 ms
コンパイル使用メモリ 203,160 KB
実行使用メモリ 18,016 KB
最終ジャッジ日時 2023-09-10 16:01:06
合計ジャッジ時間 4,562 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 19 ms
7,724 KB
testcase_16 AC 30 ms
10,860 KB
testcase_17 AC 50 ms
17,828 KB
testcase_18 AC 50 ms
17,744 KB
testcase_19 AC 51 ms
17,976 KB
testcase_20 AC 55 ms
18,016 KB
testcase_21 AC 51 ms
17,560 KB
testcase_22 AC 49 ms
17,124 KB
testcase_23 AC 41 ms
13,236 KB
testcase_24 AC 39 ms
13,048 KB
testcase_25 AC 31 ms
11,468 KB
testcase_26 AC 36 ms
12,200 KB
testcase_27 AC 16 ms
6,992 KB
testcase_28 AC 48 ms
15,636 KB
testcase_29 AC 52 ms
16,680 KB
testcase_30 AC 23 ms
8,916 KB
testcase_31 AC 34 ms
11,776 KB
testcase_32 AC 56 ms
17,824 KB
testcase_33 AC 39 ms
13,268 KB
testcase_34 AC 37 ms
12,516 KB
testcase_35 AC 19 ms
7,728 KB
testcase_36 AC 17 ms
7,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
    constexpr int64_t mod = 998244353;
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    vector<vector<int64_t>> dp(n + 1, vector<int64_t>(5)); // dp[i][j] = i-th, j - 2
    int64_t ans = 0, d = 1, r = 1;
    for (int i = 0; i < n; i++) {
        dp[i][3] += d;
        for (int j = 0; j <= 4; j++) {
            int j_next = 2 + (j - 2) * a[i];
            if (0 <= j_next and j_next <= 4) {
                dp[i + 1][j_next] += dp[i][j];
                dp[i + 1][j_next] %= mod;
            }
        }
        if (i) d *= 2;
        d %= mod;
        ans *= 2;
        ans += dp[i + 1][0];
        ans %= mod;
        r *= (mod + 1) / 2;
        r %= mod;
    }
    ans += dp[n][0];
    ans %= mod;

    cout << ans * r % mod << endl;
}
0