結果

問題 No.2219 Re:010
ユーザー kcvlexkcvlex
提出日時 2023-02-17 22:27:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 2,899 ms
コンパイル使用メモリ 138,640 KB
実行使用メモリ 6,828 KB
最終ジャッジ日時 2023-09-26 19:43:33
合計ジャッジ時間 4,290 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,560 KB
testcase_01 AC 5 ms
6,508 KB
testcase_02 AC 5 ms
6,516 KB
testcase_03 AC 9 ms
6,708 KB
testcase_04 AC 5 ms
6,568 KB
testcase_05 AC 9 ms
6,760 KB
testcase_06 AC 5 ms
6,672 KB
testcase_07 AC 7 ms
6,636 KB
testcase_08 AC 9 ms
6,828 KB
testcase_09 AC 10 ms
6,644 KB
testcase_10 AC 8 ms
6,688 KB
testcase_11 AC 8 ms
6,696 KB
testcase_12 AC 8 ms
6,648 KB
testcase_13 AC 10 ms
6,632 KB
testcase_14 AC 11 ms
6,644 KB
testcase_15 AC 11 ms
6,644 KB
testcase_16 AC 11 ms
6,632 KB
testcase_17 AC 11 ms
6,684 KB
testcase_18 AC 10 ms
6,712 KB
testcase_19 AC 9 ms
6,640 KB
testcase_20 AC 11 ms
6,640 KB
testcase_21 AC 5 ms
6,516 KB
testcase_22 AC 5 ms
6,700 KB
testcase_23 AC 5 ms
6,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <atcoder/all>

#define ALL(V) std::begin(V), std::end(V)

using modint = atcoder::modint998244353;

const int SIZE = 2e5 + 10;
modint dp[SIZE][3];
modint pow2[SIZE];

const int Z = 0;
const int ZO = 1;
const int ZOZ = 2;

int main() {
    pow2[0] = 1;
    for (int i = 1; i < SIZE; i++) pow2[i] = pow2[i - 1] * 2;

    std::string S;
    std::cin >> S;

    const int N = S.size();

    int cnt_q = 0;
    for (int i = 0; i < N; i++) {
        const char c = S[i];
        dp[i + 1][Z] = dp[i][Z];
        dp[i + 1][ZO] = dp[i][ZO];
        dp[i + 1][ZOZ] = dp[i][ZOZ];
        if (c == '?') {
            dp[i + 1][Z] *= 2;
            dp[i + 1][ZO] *= 2;
            dp[i + 1][ZOZ] *= 2;
        }
        if (c == '0' || c == '?') {
            dp[i + 1][Z] += pow2[cnt_q];
            dp[i + 1][ZOZ] += dp[i][ZO];
        }
        if (c == '1' || c == '?') {
            dp[i + 1][ZO] += dp[i][Z];
        }
        cnt_q += (c == '?');
    }

    std::cout << dp[N][ZOZ].val() << std::endl;
    return 0;
}
0