A. Array Without Local Maximums (数位dp)

A. Array Without Local Maximums

time limit per test

2 seconds

memory limit per test

512 megabytes

input

standard input

output

standard output

Ivan unexpectedly saw a present from one of his previous birthdays. It is array of nn numbers from 11 to 200200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:

a1≤a2a1≤a2,

an≤an−1an≤an−1 and

ai≤max(ai−1,ai+1)ai≤max(ai−1,ai+1) for all ii from 22 to n−1n−1.

Ivan does not remember the array and asks to find the number of ways to restore it. Restored elements also should be integers from 11 to 200200. Since the number of ways can be big, print it modulo 998244353998244353.

Input

First line of input contains one integer nn (2≤n≤1052≤n≤105) — size of the array.

Second line of input contains nn integers aiai — elements of array. Either ai=−1ai=−1 or 1≤ai≤2001≤ai≤200. ai=−1ai=−1 means that ii-th element can't be read.

Output

Print number of ways to restore the array modulo 998244353998244353.

Examples

input

Copy

3
1 -1 2

output

Copy

1

input

Copy

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int maxn = 1e5 + 10;
int a[maxn];
ll dp[2][210][3];

int main()
{
	int n; cin >> n;
	int k = 0;

	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	if (a[1] == -1)
		for (int i = 1; i <= 200; i++)
			dp[k][i][0] = 1;
	else dp[k][a[1]][0] = 1;
	
	for (int i = 2; i <= n; i++, k ^= 1)
	{
		ll s = 0;

		for (int j = 1; j <= 200; j++)
		{
			dp[k ^ 1][j][0] = (a[i] == -1 || a[i] == j) ? s : 0;
			(s += dp[k][j][0] + dp[k][j][1] + dp[k][j][2]) %= mod;
			dp[k ^ 1][j][1] = (a[i] == -1 || a[i] == j) ? dp[k][j][0] + dp[k][j][1] + dp[k][j][2] : 0;
		}
		s = 0;
		for(int j = 200; j >= 1; j--)
			dp[k ^ 1][j][2] = (a[i] == -1 || a[i] == j) ? s : 0, (s += dp[k][j][1] + dp[k][j][2]) %= mod;		
	}
	ll res = 0;
	for (int i = 1; i <= 200; i++)
		(res += dp[k][i][1] + dp[k][i][2]) %= mod;
	cout << res << endl;
}
2
-1 -1

output

Copy

200

Note

In the first example, only possible value of a2a2 is 22.

In the second example, a1=a2a1=a2 so there are 200200 different values because all restored elements should be integers between 11 and 200200.

代码:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值