結果

問題 No.3500 01 String
コンテスト
ユーザー askr58
提出日時 2026-04-17 20:46:23
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 1,528 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,630 ms
コンパイル使用メモリ 340,780 KB
実行使用メモリ 7,872 KB
最終ジャッジ日時 2026-04-17 20:46:51
合計ジャッジ時間 6,575 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#include <atcoder/modint>
using mint=atcoder::modint998244353;
struct Combination{
	int n;
	vector<mint> _fact,_factinv;

	Combination(int n):n(n){
		_fact.resize(n+1,1);_factinv.resize(n+1,1);
		for(int i=0;i<n;i++)_fact[i+1]=_fact[i]*(i+1);
		_factinv[n]=_fact[n].inv();
		for(int i=n-1;i>=0;i--)_factinv[i]=_factinv[i+1]*(i+1);
	}
	mint fact(int x){
		return _fact[x];
	}
	mint factinv(int x){	
		return _factinv[x];
	}
	mint C(int x,int y){
		assert(0<=x&&x<=n&&0<=y);
		if(x<y)return 0;
		else return _fact[x]*_factinv[y]*_factinv[x-y];
	};
	mint Cinv(int x,int y){
		assert(0<=x&&x<=n&&0<=y);
		if(x<y)return 0;
		else return _factinv[x]*_fact[y]*_fact[x-y];
	}
	mint P(int x,int y){
		assert(0<=x&&x<=n&&0<=y);
		if(x<y)return 0;
		else return _fact[x]*_factinv[x-y];
	}
	mint Pinv(int x,int y){
		assert(0<=x&&x<=n&&0<=y);
		if(x<y)return 0;
		else return _factinv[x]*_fact[x-y];
	}
	mint frac(int y,int x){
		assert(x!=0);
		if(y==0)return 0;
		else return (_fact[y]*_factinv[y-1]*_factinv[x]*_fact[x-1]);
	}
};
		
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	while(s.size()>0&&s.back()=='0')s.pop_back();
	ranges::reverse(s);
	while(s.size()>0&&s.back()=='1')s.pop_back();
	ranges::reverse(s);
	n=s.size();
	if(n==0){
		cout<<1<<endl;
		return 0;
	}
	Combination comb(n);
	mint ans=1;
	for(int i=0;i<n;i++){
		int r=i;
		while(r<n&&s[r]=='0'){
			r++;
		}
		while(r<n&&s[r]=='1'){
			r++;
		}
		ans*=r-i+1;
		i=r-1;
	}
	cout<<ans.val()<<endl;
}


0