結果

問題 No.2219 Re:010
ユーザー boatmusclesboatmuscles
提出日時 2023-02-26 18:56:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 1,215 bytes
コンパイル時間 3,711 ms
コンパイル使用メモリ 260,348 KB
実行使用メモリ 5,332 KB
最終ジャッジ日時 2023-10-12 09:29:00
合計ジャッジ時間 4,925 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 AC 6 ms
4,892 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 5 ms
4,548 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 6 ms
4,868 KB
testcase_09 AC 5 ms
4,692 KB
testcase_10 AC 4 ms
4,420 KB
testcase_11 AC 4 ms
4,348 KB
testcase_12 AC 4 ms
4,348 KB
testcase_13 AC 6 ms
5,252 KB
testcase_14 AC 7 ms
5,060 KB
testcase_15 AC 6 ms
5,052 KB
testcase_16 AC 7 ms
5,120 KB
testcase_17 AC 6 ms
5,064 KB
testcase_18 AC 5 ms
5,148 KB
testcase_19 AC 8 ms
5,048 KB
testcase_20 AC 7 ms
5,332 KB
testcase_21 AC 1 ms
4,352 KB
testcase_22 AC 1 ms
4,352 KB
testcase_23 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/extc++.h>
#include<atcoder/modint>
using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;
using Mint = modint998244353;
using mint = modint;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rep2(i, a, b) for (int i = (int)a; i < (int)(b); ++i)
#define rrep2(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); --i)
constexpr unsigned half = 499122177;

int main(){
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.length();
    int A[N];
    int sum[3] = {0,0,0};
    rep(i, N){
        A[i] = S[i] == '?' ? 2 : S[i] - '0';
        ++sum[A[i]];
    }
    Mint answer{0};
    int left[3] = {0,0,0};
    int right[3];
    Mint two[N+1];
    two[0] = 1;
    rep(i, N) two[i+1] = two[i]*2;
    rep(i, N){
        if(A[i] != 0){
            rep(j, 3) right[j] = sum[j] - left[j];
            --right[A[i]];
            answer += (Mint::raw(left[0]) + Mint::raw(left[2])*half)*(Mint::raw(right[0]) + Mint::raw(right[2])*half)*two[left[2] + right[2]];
        }
        ++left[A[i]];
    }
    cout << answer.val() << '\n';
    return 0;
}
0