This page is still under construction.

Parts of this page are still being built. What you see may change.

Gachapon

Time limit5sMemory limit512 MB

Summary
Given item frequencies and per-level round counts, compute for each star count the expected number of such items in a legal top-level rolling, times its legality probability, modulo 998244353.
Level

Hard8 of 10

Topics
Dynamic programming, Probability, Math
Solved
No attempts yet

Problem

According to Wikipedia, "a gacha game is a video game that implements the gacha (toy vending machine) mechanic". Similar to loot boxes, gacha games lead players to spend in-game currency to receive a random virtual item.

One such game is Step-up Gacha, where the chance of rolling a rare item rises each time the player rolls. For example, Genshin Impact guarantees that a player can always draw a four-star item or character within any ten consecutive rolls.

Abstracting these rolling rules helps. Consider a game with 00-star, 11-star, …\ldots, mm-star items. The probability of drawing an ii-star item in a single roll is ai∑j=0maj\frac{a_i}{\sum_{j=0}^{m} a_j}. A single draw is a level 00 rolling, and a level kk rolling consists of exactly bkb_k rounds of level (k−1)(k-1) rollings. The highest level of a rolling is nn.

A level kk rolling is legal if it ensures the following:

  • at least one item with at least kk stars is drawn,
  • for all bkb_k level (k−1)(k-1) rollings it contains, at least one item with at least (k−1)(k-1) stars is drawn,
  • and so on, down to each level 00 rolling (a single draw), for which at least one item with at least 00 stars is drawn trivially.

Let pip_i be the expected number of ii-star items drawn from a legal nn-level rolling, and let qq be the probability that an nn-level rolling is legal. Find the values of pip_i and qq. To avoid huge numbers and divisions by zero, for every 0≤i≤m0 \le i \le m, output only the value (pi⋅q) mod 998 244 353(p_i \cdot q) \bmod 998\,244\,353.

Input

The first line contains two integers mm and nn: the maximum number of stars and the highest level of a rolling (1≤n≤m≤40001 \le n \le m \le 4000).

The second line contains m+1m + 1 integers a0,a1,…,ama_0, a_1, \ldots, a_m: the frequencies of rolling items with 0,1,…,m0, 1, \ldots, m stars (1≤ai≤40001 \le a_i \le 4000).

The third line contains nn integers b1,b2,…,bnb_1, b_2, \ldots, b_n: the number of previous level rollings in a rolling of level 1,2,…,n1, 2, \ldots, n (2≤bi≤40002 \le b_i \le 4000).

Output

Output m+1m+1 lines. The ii-th line should contain a single integer: the value of (pi−1⋅q) mod 998 244 353(p_{i-1} \cdot q) \bmod 998\,244\,353.

Hint

In the first example, the answers in rational form are: 89\frac{8}{9}, 11, 11.

Examples3

  1. Example 1

    Input
    2 1
    1 1 1
    3
    
    Expected output
    554580197
    1
    1
    
  2. Example 2

    Input
    2 1
    89 10 1
    10
    
    Expected output
    989586456
    1
    299473306
    
  3. Example 3

    Input
    3 2
    1 1 2 1
    2 3
    
    Expected output
    58137752
    260406016
    517809313
    758026833