結果

問題 No.2541 Divide 01 String
ユーザー daiotadaiota
提出日時 2023-11-24 23:17:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 1,615 ms
コンパイル使用メモリ 171,368 KB
実行使用メモリ 7,876 KB
最終ジャッジ日時 2023-11-24 23:17:31
合計ジャッジ時間 2,521 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,872 KB
testcase_05 AC 7 ms
7,744 KB
testcase_06 AC 4 ms
6,676 KB
testcase_07 AC 7 ms
7,724 KB
testcase_08 AC 8 ms
7,876 KB
testcase_09 AC 7 ms
7,876 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 3 ms
6,676 KB
testcase_12 AC 3 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 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define REP(i,n) for(ll i=0;i<ll(n);i++)


const ll MOD=998244353;
ll dp[2][200010];

int main(void){
	cin.tie(nullptr);  ios_base::sync_with_stdio(false);
	ll i,j;

	ll N;
	string S;
	cin >> N >> S;

	vector<ll> v;
	REP(i,N) if(S[i]=='1') v.push_back(i);

	ll n=v.size();
	if(n==0 || n==1){
		cout << n << endl;
		return 0;
	}

	vector<ll> u;
	for(i=1;i<n;i++){
		u.push_back(v[i]-v[i-1]);
	}

	ll m=u.size();
	dp[1][0]=1;
	for(i=1;i<=m;i++){
		dp[0][i]=dp[0][i-1]+dp[1][i-1];
		dp[0][i]%=MOD;
		dp[1][i]=(dp[0][i-1]+dp[1][i-1])*u[i-1];
		dp[1][i]%=MOD;
	}

	cout << (dp[0][m]+dp[1][m])%MOD << endl;




	return 0;
}
0