結果
| 問題 | No.2219 Re:010 | 
| コンテスト | |
| ユーザー |  kcvlex | 
| 提出日時 | 2023-02-17 22:27:20 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 11 ms / 2,000 ms | 
| コード長 | 1,081 bytes | 
| コンパイル時間 | 2,881 ms | 
| コンパイル使用メモリ | 140,468 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-07-19 13:36:46 | 
| 合計ジャッジ時間 | 3,904 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
ソースコード
#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;
}
            
            
            
        