結果

問題 No.2219 Re:010
ユーザー lddlinanlddlinan
提出日時 2023-03-07 14:07:25
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,388 bytes
コンパイル時間 739 ms
コンパイル使用メモリ 84,612 KB
最終ジャッジ日時 2025-02-11 06:11:18
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 6 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   31 |     scanf("%s", ib);
      |     ~~~~~^~~~~~~~~~

ソースコード

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