結果

問題 No.2219 Re:010
ユーザー lddlinanlddlinan
提出日時 2023-03-07 14:10:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,399 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 85,560 KB
実行使用メモリ 6,560 KB
最終ジャッジ日時 2023-10-18 05:29:57
合計ジャッジ時間 2,058 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,288 KB
testcase_01 AC 2 ms
5,288 KB
testcase_02 AC 2 ms
5,288 KB
testcase_03 AC 9 ms
6,312 KB
testcase_04 AC 3 ms
5,388 KB
testcase_05 AC 8 ms
5,944 KB
testcase_06 AC 3 ms
5,464 KB
testcase_07 AC 6 ms
5,688 KB
testcase_08 AC 9 ms
6,180 KB
testcase_09 AC 9 ms
6,096 KB
testcase_10 AC 7 ms
5,864 KB
testcase_11 AC 7 ms
5,768 KB
testcase_12 AC 6 ms
5,780 KB
testcase_13 AC 11 ms
6,560 KB
testcase_14 AC 11 ms
6,560 KB
testcase_15 AC 11 ms
6,560 KB
testcase_16 AC 11 ms
6,560 KB
testcase_17 AC 10 ms
6,560 KB
testcase_18 AC 7 ms
6,560 KB
testcase_19 AC 7 ms
6,560 KB
testcase_20 AC 11 ms
6,560 KB
testcase_21 AC 2 ms
5,288 KB
testcase_22 AC 3 ms
5,288 KB
testcase_23 AC 2 ms
5,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <map>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <algorithm>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <string>
using namespace std;

bool rcmp(int a, int b) { return a>b; }
typedef long long LL;



char ib[200004];
int xs[200004];
int bb[200004*2];
#define MOD 998244353
int dp0[200004];
int dp10[200004];
int main() {
    int n, i, c, k;
    LL s, r, t;
    scanf("%s", ib);
    for (n=0; ib[n]; n++);
    bb[0]=1; for (i=0; i<=n+n; i++) {
        bb[i+1]=(bb[i]*2)%MOD;
    }
    s=0; c=0;
    dp0[n]=0;
    for (i=n-1; i>=0; i--) {
        dp0[i]=s;
        if (ib[i]=='0') s=(bb[c]+s)%MOD;
        else if (ib[i]=='?') {
            t=s; t+=s; t%=MOD; t+=bb[c]; t%=MOD; 
            s=t;
            c++;
        }
    }
    dp10[n]=0;
    s=0;
    for (i=n-1; i>=0; i--) {
        dp10[i]=s;
        if (ib[i]=='1') s=(s+dp0[i])%MOD;
        else if (ib[i]=='?') {
            t=s;t+=s; t%=MOD; t+=dp0[i]; t%=MOD;
            s=t;
        }
    }
    // for (i=0; i<n; i++) printf("%d: %d\n", i, dp10[i]);
    s=0;
    for (i=n-1; i>=0; i--) {
        if (ib[i]=='0') s=(s+dp10[i])%MOD;
        else if (ib[i]=='?') {
            t=s; t+=s; t%=MOD; t+=dp10[i]; t%=MOD;
            s=t;
        }

    }
    printf("%lld\n", s);
    return 0;
}
0