結果

問題 No.2541 Divide 01 String
ユーザー achapi
提出日時 2023-11-24 21:34:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 10 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 4,912 ms
コンパイル使用メモリ 252,184 KB
最終ジャッジ日時 2025-02-17 23:49:52
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using mint = atcoder::modint998244353;
using namespace std;
vector<pair<int, int>> RLE(string A){
	int N = A.size();
	vector<pair<int, int>> ret;
	for (int l = 0; l < N;){
		int r = l + 1;
		while (r < N and A[l] == A[r]){
			r++;
		};
		ret.push_back({A[l], r - l});
		l = r;
	}
	return ret;
}
int main(){
	int N;
	cin >> N;
	string S;
	cin >> S;
	auto P = RLE(S);
	mint ans = 1;
	int M = P.size();
	for (int i = 0; i < M; i++){
		if (P[i].first == '0'){
			if (i != 0 and i != M - 1){
				ans *= P[i].second + 2;
			}
		} else {
			ans *= mint(2).pow(P[i].second - 1);
		}
	}
	if (S.find('1') == string::npos){
		ans = 0;
	}
	cout << ans.val() << endl;
}
0