CF1349D.Slime and Biscuits

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Slime and his nn friends are at a party. Slime has designed a game for his friends to play.

At the beginning of the game, the ii-th player has aia_i biscuits. At each second, Slime will choose a biscuit randomly uniformly among all a1+a2+…+ana_1 + a_2 + \ldots + a_n biscuits, and the owner of this biscuit will give it to a random uniform player among n−1n-1 players except himself. The game stops when one person will have all the biscuits.

As the host of the party, Slime wants to know the expected value of the time that the game will last, to hold the next activity on time.

For convenience, as the answer can be represented as a rational number pq\frac{p}{q} for coprime pp and qq, you need to find the value of (p⋅q−1)mod  998 244 353(p \cdot q^{-1})\mod 998\,244\,353. You can prove that qmod  998 244 353≠0q\mod 998\,244\,353 \neq 0.

史莱姆和他的 nn 个朋友正在参加一场派对。史莱姆为朋友们设计了一个游戏。

游戏开始时,第 ii 位玩家拥有 aia_i 块饼干。每一秒,史莱姆会从全部 a1+a2+…+ana_1 + a_2 + \ldots + a_n 块饼干中均匀随机地选出一块;该饼干当前的持有者将这块饼干均匀随机地送给其余 n−1n-1 位玩家中的一位(即不能送给自己)。当某一位玩家拥有了全部饼干时,游戏结束。

作为派对主持人,史莱姆希望知道游戏持续时间的期望值,以便准时安排下一项活动。

为方便起见,由于答案可表示为既约分数 pq\frac{p}{q}(其中 pp 与 qq 互质),你需要计算 (p⋅q−1) mod 998 244 353(p \cdot q^{-1}) \bmod 998\,244\,353。可以证明 q mod 998 244 353≠0q \bmod 998\,244\,353 \neq 0。

输入格式

The first line contains one integer n (2≤n≤100 000)n\ (2\le n\le 100\,000): the number of people playing the game.

The second line contains nn non-negative integers a1,a2,…,an (1≤a1+a2+⋯+an≤300 000)a_1,a_2,\dots,a_n\ (1\le a_1+a_2+\dots+a_n\le 300\,000), where aia_i represents the number of biscuits the ii-th person own at the beginning.

第一行包含一个整数 n (2≤n≤100 000)n\ (2\le n\le 100\,000):参与游戏的人数。

第二行包含 nn 个非负整数 a1,a2,…,an (1≤a1+a2+⋯+an≤300 000)a_1,a_2,\dots,a_n\ (1\le a_1+a_2+\dots+a_n\le 300\,000),其中 aia_i 表示第 ii 个人初始拥有的饼干数量。

输出格式

Print one integer: the expected value of the time that the game will last, modulo 998 244 353998\,244\,353.

输出一个整数:游戏持续时间的期望值对 998 244 353998\,244\,353 取模的结果。

输入输出样例

  • 输入#1

    2
    1 1

    输出#1

    1
  • 输入#2

    2
    1 2

    输出#2

    3
  • 输入#3

    5
    0 0 0 0 35

    输出#3

    0
  • 输入#4

    5
    8 4 2 0 1

    输出#4

    801604029

说明/提示

For the first example, in the first second, the probability that player 11 will give the player 22 a biscuit is 12\frac{1}{2}, and the probability that player 22 will give the player 11 a biscuit is 12\frac{1}{2}. But anyway, the game will stop after exactly 11 second because only one player will occupy all biscuits after 11 second, so the answer is 11.

对于第一个样例,在第一秒内,玩家 11 将饼干给玩家 22 的概率为 12\frac{1}{2},而玩家 22 将饼干给玩家 11 的概率也为 12\frac{1}{2}。但无论如何,游戏将在恰好 11 秒后结束,因为经过 11 秒后,将只有一名玩家持有全部饼干,因此答案为 11。

输入解题思路,AI测评打分。不知道怎么写?

首页