AT_abc462_g.Completely Wrong
省选/NOI-
通过率:0%
时间限制:3.00s
内存限制:1024MB
AC君温馨提醒
该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
There is a box containing N balls numbered 1 through N. Each ball is painted with a color represented as an integer, and ball i is painted with color Ci.
Takahashi performed N operations. The k-th operation (1≤k≤N) is as follows:
- Draw one ball uniformly at random from the box and discard it. If the drawn ball has color Gk, gain 1 point.
Find the probability, modulo 998244353, that the total score over N operations is 0 points.
Definition of probability modulo 998244353
It can be proved that the sought probability is always a rational number. Furthermore, under the constraints of this problem, when the rational number is expressed as an irreducible fraction QP, it can be proved that Q≡0(mod998244353). Thus, there exists a unique integer R satisfying R×Q≡P(mod998244353) and 0≤R<998244353. Find this R.
盒中有 N 个编号为 1 至 N 的球。每个球被涂上一种颜色,颜色用整数表示;其中第 i 个球的颜色为 Ci。
高桥进行了 N 次操作。第 k 次操作(1≤k≤N)如下:
- 从盒中均匀随机抽取一个球并丢弃它。若抽到的球颜色为 Gk,则获得 1 分。
求在全部 N 次操作中总得分为 0 分的概率(对 998244353 取模)。
概率对 998244353 取模的定义
可以证明:所求概率恒为有理数。此外,在本题约束下,当该有理数表示为既约分数 QP 时,可证 Q≡0(mod998244353)。因此,存在唯一整数 R 满足 R×Q≡P(mod998244353) 且 0≤R<998244353。请输出该 R。
输入格式
The input is given from Standard Input in the following format:
N
C1 C2 … CN
G1 G2 … GN
输入从标准输入中按以下格式给出:
N
C1 C2 … CN
G1 G2 … GN
输出格式
Output the sought probability modulo 998244353.
输出所求概率对 998244353 取模的结果。
输入输出样例
输入#1
3 1 2 3 1 1 2
输出#1
332748118
输入#2
3 1 1 3 3 3 3
输出#2
0
输入#3
6 1 2 3 3 4 5 3 5 3 5 5 4
输出#3
316110712
说明/提示
Sample 1 Explanation:
For example, the operations may proceed as follows:
- First operation: A ball with color 2 is drawn from the box.
- Second operation: A ball with color 1 is drawn from the box. Gain 1 point.
- Third operation: A ball with color 3 is drawn from the box.
In this case, the total score is 1 point.
The probability that Takahashi's total score is 0 is 31.
Sample 2 Explanation:
Takahashi's total score is always 1 point.
Constraints
- 1≤N≤2×105
- 1≤Ci,Gk≤N
- All input values are integers.
样例 1 解释:
例如,操作过程可能如下所示:
- 第一次操作:从盒子中抽出一个颜色为 2 的球。
- 第二次操作:从盒子中抽出一个颜色为 1 的球,获得 1 分。
- 第三次操作:从盒子中抽出一个颜色为 3 的球。
此时,总得分为 1 分。
高桥的总得分等于 0 的概率为 31。
样例 2 解释:
高桥的总得分恒为 1 分。
限制条件
- 1≤N≤2×105
- 1≤Ci,Gk≤N
- 所有输入值均为整数。
输入解题思路,AI测评打分。不知道怎么写?