結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
5,380 KB
testcase_02 AC 2 ms
5,380 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 7 ms
6,652 KB
testcase_19 AC 8 ms
6,652 KB
testcase_20 AC 11 ms
6,652 KB
testcase_21 AC 2 ms
5,380 KB
testcase_22 AC 2 ms
5,380 KB
testcase_23 AC 2 ms
5,380 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++;
        }
    }
    // for (i=0; i<n; i++) printf("%d: %d\n", i, dp0[i]);
    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;
        }
    }
    r=0;  s=0;
    for (i=n-1; i>=0; i--) {
        if (ib[i]=='0') s=(s+dp10[i])%MOD;
        else {
            t=s; t+=s; t%=MOD; t+=dp10[i]; t%=MOD;
            s=t;
        }

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