CF1172C1.Nauuo and Pictures (easy version)
提高+/省选-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The only difference between easy and hard versions is constraints.
Nauuo is a girl who loves random picture websites.
One day she made a random picture website by herself which includes n pictures.
When Nauuo visits the website, she sees exactly one picture. The website does not display each picture with equal probability. The i-th picture has a non-negative weight wi, and the probability of the i-th picture being displayed is ∑j=1nwjwi. That is to say, the probability of a picture to be displayed is proportional to its weight.
However, Nauuo discovered that some pictures she does not like were displayed too often.
To solve this problem, she came up with a great idea: when she saw a picture she likes, she would add 1 to its weight; otherwise, she would subtract 1 from its weight.
Nauuo will visit the website m times. She wants to know the expected weight of each picture after all the m visits modulo 998244353. Can you help her?
The expected weight of the i-th picture can be denoted by piqi where gcd(pi,qi)=1, you need to print an integer ri satisfying 0≤ri<998244353 and ri⋅pi≡qi(mod998244353). It can be proved that such ri exists and is unique.
简单版本与困难版本的唯一区别在于约束条件。
Nauuo 是一位喜爱随机图片网站的女孩。
某天,她自己创建了一个随机图片网站,其中包含 n 张图片。
当 Nauuo 访问该网站时,她恰好看到一张图片。该网站并非以相等的概率显示每张图片。第 i 张图片具有一个非负权重 wi,其被显示的概率为 ∑j=1nwjwi。换言之,一张图片被显示的概率与其权重成正比。
然而,Nauuo 发现,一些她不喜欢的图片出现得过于频繁。
为解决这一问题,她想出了一个绝妙的主意:当她看到一张喜欢的图片时,就将其权重加 1;否则,就将其权重减 1。
Nauuo 将访问该网站 m 次。她希望知道经过全部 m 次访问后,每张图片的期望权重(对 998244353 取模)。你能帮她吗?
第 i 张图片的期望权重可表示为 piqi,其中 gcd(pi,qi)=1。你需要输出一个整数 ri,满足 0≤ri<998244353 且 ri⋅pi≡qi(mod998244353)。可以证明这样的 ri 存在且唯一。
输入格式
The first line contains two integers n and m (1≤n≤50, 1≤m≤50) — the number of pictures and the number of visits to the website.
The second line contains n integers a1,a2,…,an (ai is either 0 or 1) — if ai=0 , Nauuo does not like the i-th picture; otherwise Nauuo likes the i-th picture. It is guaranteed that there is at least one picture which Nauuo likes.
The third line contains n integers w1,w2,…,wn (1≤wi≤50) — the initial weights of the pictures.
第一行包含两个整数 n 和 m(1≤n≤50,1≤m≤50)—— 分别表示图片数量和网站访问次数。
第二行包含 n 个整数 a1,a2,…,an(每个 ai 为 0 或 1)—— 若 ai=0,则 Nauuo 不喜欢第 i 张图片;否则 Nauuo 喜欢第 i 张图片。保证至少存在一张 Nauuo 喜欢的图片。
第三行包含 n 个整数 w1,w2,…,wn(1≤wi≤50)—— 表示各张图片的初始权重。
输出格式
The output contains n integers r1,r2,…,rn — the expected weights modulo 998244353.
输出包含 n 个整数 r1,r2,…,rn —— 即期望权重对 998244353 取模的结果。
输入输出样例
输入#1
2 1 0 1 2 1
输出#1
332748119 332748119
输入#2
1 2 1 1
输出#2
3
输入#3
3 3 0 1 1 4 3 5
输出#3
160955686 185138929 974061117
说明/提示
In the first example, if the only visit shows the first picture with a probability of 32, the final weights are (1,1); if the only visit shows the second picture with a probability of 31, the final weights are (2,2).
So, both expected weights are 32⋅1+31⋅2=34 .
Because 332748119⋅3≡4(mod998244353), you need to print 332748119 instead of 34 or 1.3333333333.
In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, w1 will be increased by 1.
So, the expected weight is 1+2=3.
Nauuo is very naughty so she didn't give you any hint of the third example.
在第一个例子中,若唯一的一次访问展示第一张图片(概率为 32),则最终权重为 (1,1);若唯一的一次访问展示第二张图片(概率为 31),则最终权重为 (2,2)。
因此,两个权重的期望值均为 32⋅1+31⋅2=34。
由于 332748119⋅3≡4(mod998244353),你需要输出 332748119,而非 34 或 1.3333333333。
在第二个例子中,只有一张 Nauuo 喜欢的图片,因此每次 Nauuo 访问网站时,w1 都会增加 1。
因此,期望权重为 1+2=3。
Nauuo 非常调皮,因此她没有给你第三个例子的任何提示。
输入解题思路,AI测评打分。不知道怎么写?