A12602 | Nauuo and Pictures (easy version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $w_i$ , and the probability of the $i$ -th picture being displayed is $\frac{w_i}{\sum_{j=1}^nw_j}$ . 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 $\frac {q_i} {p_i}$ where $\gcd(p_i,q_i)=1$ , you need to print an integer $r_i$ satisfying $0\le r_i<998244353$ and $r_i\cdot p_i\equiv q_i\pmod{998244353}$ . It can be proved that such $r_i$ exists and is unique.
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 $w_i$ , and the probability of the $i$ -th picture being displayed is $\frac{w_i}{\sum_{j=1}^nw_j}$ . 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 $\frac {q_i} {p_i}$ where $\gcd(p_i,q_i)=1$ , you need to print an integer $r_i$ satisfying $0\le r_i<998244353$ and $r_i\cdot p_i\equiv q_i\pmod{998244353}$ . It can be proved that such $r_i$ exists and is unique.
输入格式
The first line contains two integers $n$ and $m$ ( $1\le n\le 50$ , $1\le m\le 50$ ) — the number of pictures and the number of visits to the website.
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $a_i$ is either $0$ or $1$ ) — if $a_i=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 $w_1,w_2,\ldots,w_n$ ( $1\le w_i\le50$ ) — the initial weights of the pictures.
The second line contains $n$ integers $a_1,a_2,\ldots,a_n$ ( $a_i$ is either $0$ or $1$ ) — if $a_i=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 $w_1,w_2,\ldots,w_n$ ( $1\le w_i\le50$ ) — the initial weights of the pictures.
输出格式
The output contains $n$ integers $r_1,r_2,\ldots,r_n$ — the expected weights modulo $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 $\frac 2 3$ , the final weights are $(1,1)$ ; if the only visit shows the second picture with a probability of $\frac1 3$ , the final weights are $(2,2)$ .
So, both expected weights are $\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3$ .
Because $332748119\cdot 3\equiv 4\pmod{998244353}$ , you need to print $332748119$ instead of $\frac4 3$ or $1.3333333333$ .
In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $w_1$ 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.
So, both expected weights are $\frac2 3\cdot 1+\frac 1 3\cdot 2=\frac4 3$ .
Because $332748119\cdot 3\equiv 4\pmod{998244353}$ , you need to print $332748119$ instead of $\frac4 3$ or $1.3333333333$ .
In the second example, there is only one picture which Nauuo likes, so every time Nauuo visits the website, $w_1$ 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted