結果
| 問題 | No.2219 Re:010 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-03-07 14:10:12 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 10 ms / 2,000 ms | 
| コード長 | 1,399 bytes | 
| コンパイル時間 | 640 ms | 
| コンパイル使用メモリ | 83,972 KB | 
| 最終ジャッジ日時 | 2025-02-11 06:11:41 | 
| ジャッジサーバーID (参考情報) | judge3 / judge6 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 21 | 
コンパイルメッセージ
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);
      |     ~~~~~^~~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        