Playlist

AtCoder
IDabc323_e
Time2000ms
Memory256MB
Difficulty
Takahashi has a playlist with $N$ songs. Song $i$ $(1 \leq i \leq N)$ lasts $T_i$ seconds. Takahashi has started random play of the playlist at time $0$. Random play repeats the following: choose one song from the $N$ songs with equal probability and play that song to the end. Here, songs are played continuously: once a song ends, the next chosen song starts immediately. The same song can be chosen consecutively. Find the probability that song $1$ is being played $(X + 0.5)$ seconds after time $0$, modulo $998244353$. How to print a probability modulo $998244353$It can be proved that the probability to be found in this problem is always a rational number. Also, the constraints of this problem guarantee that when the probability to be found is expressed as an irreducible fraction $\frac{y}{x}$, $x$ is not divisible by $998244353$. Then, there is a unique integer $z$ between $0$ and $998244352$, inclusive, such that $xz \equiv y \pmod{998244353}$. Report this $z$. ## Constraints * $2 \leq N\leq 10^3$ * $0 \leq X\leq 10^4$ * $1 \leq T_i\leq 10^4$ * All input values are integers. ## Input The input is given from Standard Input in the following format: $N$ $X$ $T_1$ $T_2$ $\ldots$ $T_N$ [samples]
Samples
Input #1
3 6
3 5 6
Output #1
369720131

Song $1$ will be playing $6.5$ seconds after time $0$ if songs are played in one of the following orders.

*   Song $1$ $\to$ Song $1$ $\to$ Song $1$
*   Song $2$ $\to$ Song $1$
*   Song $3$ $\to$ Song $1$

The probability that one of these occurs is $\frac{7}{27}$.  
We have $369720131\times 27\equiv 7 \pmod{998244353}$, so you should print $369720131$.
Input #2
5 0
1 2 1 2 1
Output #2
598946612

$0.5$ seconds after time $0$, the first song to be played is still playing, so the sought probability is $\frac{1}{5}$.  
Note that different songs may have the same length.
Input #3
5 10000
1 2 3 4 5
Output #3
586965467
API Response (JSON)
{
  "problem": {
    "name": "Playlist",
    "description": {
      "content": "Takahashi has a playlist with $N$ songs. Song $i$ $(1 \\leq i \\leq N)$ lasts $T_i$ seconds.   Takahashi has started random play of the playlist at time $0$. Random play repeats the following: choose on",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "abc323_e"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Takahashi has a playlist with $N$ songs. Song $i$ $(1 \\leq i \\leq N)$ lasts $T_i$ seconds.  \nTakahashi has started random play of the playlist at time $0$.\nRandom play repeats the following: choose on...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments