luogu#P16329. bloom

    ID: 16156 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP洛谷原创O2优化动态规划优化前缀和洛谷月赛

bloom

Problem Description

You are given n,mn,m and two sequences aia_i and pip_i of length nn. Some values of aia_i are fixed, while some are unknown. Each position also has a type, either 00 or 11. You need to assign values to the unknown aia_i so that ai1a_i \ge 1 and ai=m\sum a_i = m.

For every possible assignment of aa, consider the following game. Compute the sum of the game's weight over all assignments of aa, modulo 998244353998244353.

  • The game consists of 2n2^n rounds. At the beginning of the xx-th round, the health of the ii-th player, denoted by bib_i, is set to aia_i, and their type is determined by the (i1)(i-1)-th bit in the binary representation of x1x-1. Here, xx is indexed from 11.

  • At the beginning of each round, all people of type 11 start moving to the right simultaneously, while people of type 00 stay still. Everyone moves one cell per unit time.

  • Whenever a type-11 person meets a type-00 person, suppose their indices are i,ji,j, and let t=min(bi,bj)t=\min(b_i,b_j). Then perform simultaneously: bibit, bjbjtb_i \leftarrow b_i - t,\ b_j \leftarrow b_j - t. Any person with bi=0b_i=0 disappears.

  • The weight of this round is the product of the initial pp values of all people still existing after 1010010^{100} units of time.

  • The weight of the game is the sum of the weights of all 2n2^n rounds.

Input Format

The first line contains two positive integers n,mn,m.

The second line contains nn non-negative integers aia_i, where ai=0a_i=0 indicates that this position is undetermined.

The third line contains nn positive integers pip_i, representing the initial weight of each person.

Output Format

Output a single integer — the sum of the game weights over all valid assignments, modulo 998244353998244353.

2 3
1 2
2 2
14
4 4
1 1 0 0
2 2 3 3
239

6 10
0 1 1 0 0 2
743619643 294476845 718152187 194051637 59774782 188785641
285625840

Hint

Sample Explanation 1

The game lasts for 44 rounds:

  • In the 11-st round, the types of the two players are 00 and 00. Both of them survive until the end, so the weight is 2×2=42 \times 2 = 4.
  • In the 22-nd round, the types of the two players are 11 and 00. After 11 unit of time, they collide, and their health becomes 00 and 11. Only the second player survives, so the weight is 22.
  • In the 33-rd round, the types of the two players are 00 and 11. Both of them survive until the end, so the weight is 44.
  • In the 44-th round, the types of the two players are 11 and 11. Both of them survive until the end, so the weight is 44.

Thus, the answer is 4+2+4+4=144 + 2 + 4 + 4 = 14.

Constraints

For all test cases, 1n,m5001\le n,m\le 500, 0aim0\le a_i \le m, 1pi<9982443531\le p_i < 998244353, and it is guaranteed that there exists at least one valid assignment of aa.

Subtask n,mn,m\le Special Property Score
11 88 None 1010
22 5050 2020
33 100100
44 500500 Yes
55 None 3030
  • Special property: It is guaranteed that m=nm=n.