CF1799G.Count Voting

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

There are nn people that will participate in voting. Each person has exactly one vote.

ii-th person has a team tit_i (1≤ti≤n1 \leq t_i \leq n) where ti=tjt_i = t_j means ii, jj are in the same team. By the rules each person should vote for the person from the different team. Note that it automatically means that each person can't vote for himself.

Each person knows the number of votes cic_i he wants to get. How many possible votings exists, such that each person will get the desired number of votes? Due to this number can be big, find it by modulo 998 244 353998\,244\,353.

共有 nn 人将参与投票,每人恰好拥有一票。

第 ii 个人所属的队伍为 tit_i(1≤ti≤n1 \leq t_i \leq n),其中 ti=tjt_i = t_j 表示第 ii 人与第 jj 人属于同一支队伍。根据规则,每人必须将票投给其他队伍中的一人(即不能投给自己所在队伍的任何人)。注意,该规则自动保证了每人不能投给自己。

每个人都知道自己希望获得的票数 cic_i。问:有多少种可能的投票方案,使得每人最终恰好获得其期望的票数?由于该数目可能很大,请对 998 244 353998\,244\,353 取模后输出结果。

输入格式

The first line contains a single integer nn (1≤n≤2001 \leq n \leq 200) — the number of people.

The second line contains nn integers c1,c2,…,cnc_1, c_2, \ldots, c_n (0≤ci≤n0 \leq c_i \leq n) — desired number of votes. It is guaranteed, that ∑i=1nci=n\sum\limits_{i=1}^{n} c_i = n.

The third line contains nn integers t1,t2,…,tnt_1, t_2, \ldots, t_n (1≤ti≤n1 \leq t_i \leq n) — team numbers.

第一行包含一个整数 nn(1≤n≤2001 \leq n \leq 200)—— 人数。

第二行包含 nn 个整数 c1,c2,…,cnc_1, c_2, \ldots, c_n(0≤ci≤n0 \leq c_i \leq n)—— 各人期望的票数。保证 ∑i=1nci=n\sum\limits_{i=1}^{n} c_i = n。

第三行包含 nn 个整数 t1,t2,…,tnt_1, t_2, \ldots, t_n(1≤ti≤n1 \leq t_i \leq n)—— 所属队伍编号。

输出格式

Print a single integer — the number of possible votings by modulo 998 244 353998\,244\,353.

输出一个整数——模 998 244 353998\,244\,353 意义下可能的投票方案数。

输入输出样例

  • 输入#1

    3
    1 1 1
    1 2 3

    输出#1

    2
  • 输入#2

    5
    2 0 1 0 2
    1 2 3 4 5

    输出#2

    10
  • 输入#3

    5
    1 2 2 0 0
    3 5 4 3 4

    输出#3

    5

说明/提示

In the first test there are two possible votings: (2,3,1)(2, 3, 1), (3,1,2)(3, 1, 2).

In the third test there are five possible votings: (3,3,2,2,1)(3, 3, 2, 2, 1), (2,3,2,3,1)(2, 3, 2, 3, 1), (3,3,1,2,2)(3, 3, 1, 2, 2), (3,1,2,3,2)(3, 1, 2, 3, 2), (2,3,1,3,2)(2, 3, 1, 3, 2).

在第一个测试中,存在两种可能的投票方案:(2,3,1)(2, 3, 1)、(3,1,2)(3, 1, 2)。

在第三个测试中,存在五种可能的投票方案:(3,3,2,2,1)(3, 3, 2, 2, 1)、(2,3,2,3,1)(2, 3, 2, 3, 1)、(3,3,1,2,2)(3, 3, 1, 2, 2)、(3,1,2,3,2)(3, 1, 2, 3, 2)、(2,3,1,3,2)(2, 3, 1, 3, 2)。

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

首页