CF2172D.Divisor Card Game
NOI/NOI+/CTSC
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
In Taiwan, many mathematics teachers design board and card games to help students grasp difficult mathematical concepts. Recently, a particular card game has gone viral among elementary and middle school teachers because it effectively helps students understand the concepts of divisors and multiples, while also being highly engaging for both teachers and students.
The rules of the game are as follows. The teacher prepares n distinct cards, labeled from 1 to n. The i-th card has an integer value ai written on it, and the integers a1,a2,…,an are in a strictly increasing order.
There are m students labeled from 1 to m participating in the game. Before the game begins, each student receives a nonempty subset of the n cards. No two students share any card, and at least one card remains undealt.
Let k denote the number of undealt cards initially. The game consists of k rounds. In each round, the following steps occur in order:
- The teacher selects one of the remaining undealt cards uniformly at random and reveals it to all students. Let c be the integer written on this card.
- Each student simultaneously chooses exactly one card from their own collection.
- The ownership of the revealed card is determined as follows:
- Among the values of all cards chosen by the students, consider those that are divisible by c.
- If there are one or more such values, the student who selected a card with the smallest divisible value wins the revealed card and adds it to their collection.
- If no chosen cards have value divisible by c, the revealed card is discarded (remains unowned). Discarded cards are not used in subsequent rounds.
Each student follows the same strategy throughout the game:
- If the student owns at least one card whose value is divisible by c, they choose the card with the smallest value.
- Otherwise, they choose the card with the smallest value among those they own.
Assuming that all students follow this strategy in every round, determine the expected number of cards that each student will own at the end of the game.
在台湾,许多数学教师设计棋盘游戏和纸牌游戏,以帮助学生掌握较难的数学概念。最近,一款特定的纸牌游戏在小学和初中教师中迅速走红,因为它能有效帮助学生理解“因数”与“倍数”的概念,同时对师生双方都极具吸引力。
游戏规则如下:教师准备 n 张互不相同的卡片,编号为 1 至 n。第 i 张卡片上写有一个整数值 ai,且整数序列 a1,a2,…,an 严格递增。
共有 m 名学生参与游戏,编号为 1 至 m。游戏开始前,每名学生分得 n 张卡片的一个非空子集;任意两名学生所持卡片互不重叠,且至少有一张卡片未被分发。
设初始未分发卡片的数量为 k。整个游戏共进行 k 轮。每轮按以下顺序执行:
- 教师从当前剩余的未分发卡片中等概率随机选取一张,并向所有学生展示。设该卡片上的整数为 c。
- 每名学生同时从自己持有的卡片中恰好选择一张。
- 所展示卡片的归属按如下规则确定:
- 考察所有学生所选卡片的数值中,能被 c 整除的那些值;
- 若存在至少一个这样的值,则所选数值最小的该类学生赢得这张展示卡片,并将其加入自己的卡片集合;
- 若没有任何学生所选卡片的数值能被 c 整除,则该展示卡片被弃置(无人获得);弃置卡片不再参与后续轮次。
每名学生在整个游戏中均采用完全相同的策略:
- 若该学生手中至少拥有一张数值能被 c 整除的卡片,则他/她选择其中数值最小的一张;
- 否则,他/她选择自己手中数值最小的一张卡片。
假设所有学生在每一轮中均严格遵循上述策略,求游戏结束时,每名学生最终所持卡片数量的期望值。
输入格式
The first line contains two integers n and m, representing the number of cards and the number of students, respectively.
The second line contains n integers a1,a2,…,an, where ai is the integer on the i-th card.
The third line contains n integers b1,b2,…,bn, where bi describes the ownership of the i-th card before the game begins: it is owned by the bi-th student if bi=0, and is undealt otherwise.
- 1≤m<n≤600
- 1≤ai≤1018
- 0≤bi≤m
- ai<ai+1 for all 1≤i<n.
- There is at least one i such that bi=j for j=0,1,…,m.
第一行包含两个整数 n 和 m,分别表示卡片的数量和学生的数量。
第二行包含 n 个整数 a1,a2,…,an,其中 ai 表示第 i 张卡片上的整数。
第三行包含 n 个整数 b1,b2,…,bn,其中 bi 描述了游戏开始前第 i 张卡片的归属情况:若 bi=0,则该卡片属于第 bi 号学生;否则(即 bi=0)该卡片尚未分发。
- 1≤m<n≤600
- 1≤ai≤1018
- 0≤bi≤m
- 对所有 1≤i<n,有 ai<ai+1。
- 对每个 j=0,1,…,m,至少存在一个 i 使得 bi=j。
输出格式
Print m numbers in a new line, where the i-th number represents the expected number of cards the i-th student will own at the end of the game.
It can be proven that each answer can be represented by a rational number qp where q is not a multiple of 998244353. Therefore, you are asked to print p×q−1 modulo 998244353 for each number, where q−1 means the multiplicative inverse of q modulo 998244353.
在新行中输出 m 个数,其中第 i 个数表示游戏结束时第 i 位学生所拥有的卡片数量的期望值。
可以证明,每个答案均可表示为有理数 qp,且 q 不是 998244353 的倍数。因此,对于每个数,你需要输出 p×q−1mod998244353,其中 q−1 表示 q 在模 998244353 意义下的乘法逆元。
输入输出样例
输入#1
5 2 1 2 3 4 5 0 0 1 2 1
输出#1
499122179 499122179
输入#2
6 2 1 2 3 4 5 6 0 0 0 1 0 2
输出#2
831870297 166374061
输入#3
8 3 4 5 8 9 12 18 20 24 0 0 0 0 0 2 1 3
输出#3
332748120 2 665496239
输入解题思路,AI测评打分。不知道怎么写?