結果
問題 | No.2541 Divide 01 String |
ユーザー |
|
提出日時 | 2023-11-24 23:17:28 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 8 ms / 2,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 1,521 ms |
コンパイル使用メモリ | 169,996 KB |
実行使用メモリ | 6,720 KB |
最終ジャッジ日時 | 2024-09-26 09:46:08 |
合計ジャッジ時間 | 2,344 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#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;}