結果

問題 No.2541 Divide 01 String
ユーザー achapiachapi
提出日時 2023-11-24 21:34:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 9 ms / 2,000 ms
コード長 704 bytes
コンパイル時間 4,299 ms
コンパイル使用メモリ 265,052 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-11-24 21:34:37
合計ジャッジ時間 5,243 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 5 ms
6,676 KB
testcase_05 AC 9 ms
6,676 KB
testcase_06 AC 5 ms
6,676 KB
testcase_07 AC 9 ms
6,676 KB
testcase_08 AC 9 ms
6,676 KB
testcase_09 AC 9 ms
6,676 KB
testcase_10 AC 6 ms
6,676 KB
testcase_11 AC 6 ms
6,676 KB
testcase_12 AC 6 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 5 ms
6,676 KB
testcase_19 AC 4 ms
6,676 KB
testcase_20 AC 5 ms
6,676 KB
testcase_21 AC 4 ms
6,676 KB
testcase_22 AC 4 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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