結果

問題 No.2219 Re:010
ユーザー umezoumezo
提出日時 2023-02-17 22:40:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 835 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 201,268 KB
実行使用メモリ 8,236 KB
最終ジャッジ日時 2023-09-26 19:59:02
合計ジャッジ時間 3,340 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,616 KB
testcase_01 AC 4 ms
4,600 KB
testcase_02 AC 4 ms
4,676 KB
testcase_03 AC 10 ms
7,568 KB
testcase_04 AC 4 ms
5,016 KB
testcase_05 AC 9 ms
7,052 KB
testcase_06 AC 5 ms
5,404 KB
testcase_07 AC 7 ms
6,100 KB
testcase_08 AC 10 ms
7,368 KB
testcase_09 AC 9 ms
7,420 KB
testcase_10 AC 8 ms
6,656 KB
testcase_11 AC 7 ms
6,400 KB
testcase_12 AC 8 ms
6,396 KB
testcase_13 AC 11 ms
8,116 KB
testcase_14 AC 11 ms
8,236 KB
testcase_15 AC 11 ms
8,104 KB
testcase_16 AC 11 ms
8,176 KB
testcase_17 AC 11 ms
8,068 KB
testcase_18 AC 7 ms
8,108 KB
testcase_19 AC 8 ms
8,164 KB
testcase_20 AC 10 ms
8,188 KB
testcase_21 AC 4 ms
4,452 KB
testcase_22 AC 4 ms
4,408 KB
testcase_23 AC 3 ms
4,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int MOD=998244353;
int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  vector<ll> P(200200);
  P[0]=1;
  for(int i=1;i<200200;i++) P[i]=P[i-1]*2%MOD;

  string s;
  cin>>s;
  int n=s.size();
  vector<ll> L(n),R(n);
  int l=0,l0=0;
  rep(i,n){
    L[i]=l0*P[l]%MOD;
    if(l) L[i]=(L[i]+l*P[l-1]%MOD)%MOD;
    if(s[i]=='0') l0++;
    else if(s[i]=='?') l++;
  }
  int r=0,r0=0;
  for(int i=n-1;i>=0;i--){
    R[i]=r0*P[r]%MOD;
    if(r) R[i]=(R[i]+r*P[r-1]%MOD)%MOD;
    if(s[i]=='0') r0++;
    else if(s[i]=='?') r++;
  }
  ll ans=0;
  for(int i=1;i<n-1;i++){
    if(s[i]=='0') continue;
    ans=(ans+L[i]*R[i]%MOD)%MOD;
  }
  cout<<ans<<endl;
  
  return 0;
}
0