Problem Statement
Array Description
Implementation
void solve()
{
ll n, m;
cin >> n >> m;
vll a(n);
rep(i, n) cin >> a[i];
vvll dp(n + 1, vll(m + 1, 0));
if (a[0])
dp[0][a[0]] = 1;
else
FOR(j, 1, m)
dp[0][j] = 1;
FOR(i, 1, n - 1)
{
if (a[i])
{
FOR(k, -1, 1)
{
ll x = a[i] - k;
if (x > 0 && x <= m)
dp[i][a[i]] += dp[i - 1][x];
dp[i][a[i]] %= mod;
}
}
else
{
FOR(j, 1, m)
{
FOR(k, -1, 1)
{
ll x = j - k;
if (x > 0 && x <= m)
dp[i][j] += dp[i - 1][x];
dp[i][j] %= mod;
}
}
}
}
debug(dp);
ll ans = 0LL;
FOR(j, 1, m)
ans += dp[n - 1][j], ans %= mod;
cout << ans << "\n";
}