結果
| 問題 | No.2219 Re:010 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-02-17 23:42:26 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 2,000 ms |
| コード長 | 1,146 bytes |
| コンパイル時間 | 2,122 ms |
| コンパイル使用メモリ | 196,188 KB |
| 最終ジャッジ日時 | 2025-02-10 18:21:59 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
const ll MOD=998244353;
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin>>s;
int n=s.size();
vector<ll>P(n+1);
P[0]=1;
rep(i,n)P[i+1]=2*P[i]%MOD;
vector<int>X(n+1),Y(n+1);
rep(i,n){
X[i+1]=X[i];
Y[i+1]=Y[i];
if(s[i]=='0')X[i+1]++;
if(s[i]=='?')Y[i+1]++;
}
ll ans=0;
rep(i,n){
ll xl=X[i],xr=X[n]-X[i];
ll yl=Y[i],yr=Y[n]-Y[i];
if(s[i]=='?')yr--;
if(s[i]!='0'){
ll c=1;
c*=(xl*P[yl]+yl*(yl==0?0:P[yl-1]))%MOD;
c%=MOD;
c*=(xr*P[yr]+yr*(yr==0?0:P[yr-1]))%MOD;
c%=MOD;
ans+=c;
ans%=MOD;
}
}
cout<<ans<<"\n";
}