結果

問題 No.2040 010-1 Deletion
コンテスト
ユーザー askr58
提出日時 2026-07-19 19:18:56
言語 C++23
(gcc 15.2.0 + boost 1.90.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 11 ms / 3,000 ms
+ 707µs
コード長 1,450 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,165 ms
コンパイル使用メモリ 196,056 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2026-07-19 19:18:59
合計ジャッジ時間 3,356 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
#include <ranges>
#include <algorithm>
#include <vector>
#include <atcoder/modint>
using mint=atcoder::modint998244353;
using namespace std;
using ll=long long;
int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	string s;
	cin>>s;
	vector<vector<mint>> dp1(2,vector<mint>(n+1));
	vector<mint> dp2(n+1);
	dp1[0][0]=1;
	for(int i=0;i<n;i++){
		vector<vector<mint>> ndp1(2,vector<mint>(n+1));
		vector<mint> ndp2(n+1);
		if(s[i]!='0'){
			for(int j=0;j<n;j++){
				// 0^jから
				if(j==0)ndp1[0][0]+=dp1[0][0];
				else if(j==1)ndp2[2]+=dp1[0][j];
				else ndp1[1][j]+=dp1[0][j];
				// (0^j)1から
				if(j>=2)ndp1[1][j]+=dp1[1][j];
				//(01)^mから
				if(j>=2&&j%2==0)ndp2[j]+=dp2[j];
				else if(j>=2)ndp2[j+1]+=dp2[j];
			}
		}
		if(s[i]!='1'){
			for(int j=0;j<n;j++){
				//0^jから
				ndp1[0][j+1]+=dp1[0][j];
				//(0^j)1から
				if(j>=2)ndp1[0][j-1]+=dp1[1][j];
				//(01)^mから
				if(j>=2&&j%2==0)ndp2[j+1]+=dp2[j];
				else if(j>=2){
					if(j==3)ndp1[0][1]+=dp2[j];
					else ndp2[j-2]+=dp2[j];
				}
			}
		}
		dp1=ndp1;
		dp2=ndp2;
		/*
		for(int i=0;i<=n;i++)cout<<dp1[0][i].val()<<" ";
		cout<<endl;
		for(int i=0;i<=n;i++)cout<<dp1[1][i].val()<<" ";
		cout<<endl;
		for(int i=0;i<=n;i++)cout<<dp2[i].val()<<" ";
		cout<<endl;
		cout<<endl;
		//*/
	}
	mint ans=dp1[0][0];
	for(int i=2;i<=n;i++){
		if(i%4==0||i%4==3)ans+=dp2[i];
	}
	cout<<ans.val()<<endl;
}
0