tokitsukazeとセグメンテーション
知識ポイントを含みます:
解決:
- 謝罪するすべてのルートの最初に、この項目の難易度ビット大きなQAQ
- DPで割ったサブストリングの数は、[I]この実施例では、接頭文字列S1S2 .... SIを表します。
- あなたはSを[i]はSI-1は、DPする分割数の文字列のプレフィックススキームを差し引く、私は、最後の位置がこの位置私の前に分割されていない位置の後に、すべての位置0で発生した場合は、[I-1]
STD:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 100005;
const ll mod = 998244353;
char s[maxn];
ll dp[maxn];
int main()
{
int n;
scanf("%d",&n);
scanf("%s",s+1);
ll ans = 1;
int cnt = 0;
dp[0] = 1;
for(int i=1;i<=n;i++){
cnt = (cnt + (s[i]-'0'))%3;
if(cnt)continue ;
dp[i] = ans ;
if(s[i] == '0')
ans = (ans - dp[i-1] + mod)%mod;
ans = (ans + dp[i])%mod;
}
cout<<dp[n]<<endl;
return 0;
}