結果
| 問題 |
No.2219 Re:010
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-08 17:12:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 54 ms / 2,000 ms |
| コード長 | 1,235 bytes |
| コンパイル時間 | 809 ms |
| コンパイル使用メモリ | 102,824 KB |
| 最終ジャッジ日時 | 2025-02-15 09:06:39 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 21 |
ソースコード
#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);
ll mod_pow(ll x,ll y,ll mod){
ll res=1;
while(y>0){
if(y&1){
res*=x;
res%=mod;
}
x*=x;
x%=mod;
y/=2;
}
return res;
}
int main(){
string S;
cin>>S;
int n=S.size();
vector<vector<ll>> dp(n+1,vector<ll>(4,0));
dp[0][0]=1;
for(int i=0;i<n;i++){
if(S[i]=='0'){
dp[i+1][1]+=dp[i][0];
dp[i+1][3]+=dp[i][2];
}
else if(S[i]=='1'){
dp[i+1][2]+=dp[i][1];
}else{
dp[i+1][1]+=dp[i][0];
dp[i+1][3]+=dp[i][2];
dp[i+1][2]+=dp[i][1];
}
for(int j=0;j<4;j++){
dp[i+1][j]%=MOD;
}
for(int j=0;j<4;j++){
dp[i+1][j]+=dp[i][j]*(S[i]=='?'?2:1)%MOD;
dp[i+1][j]%=MOD;
}
}
ll ans=dp[n][3];
cout<<ans<<endl;
}