A16016 | Tenzing and Random Real Numbers
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are $n$ uniform random real variables between 0 and 1, inclusive, which are denoted as $x_1, x_2, \ldots, x_n$ .
Tenzing has $m$ conditions. Each condition has the form of $x_i+x_j\le 1$ or $x_i+x_j\ge 1$ .
Tenzing wants to know the probability that all the conditions are satisfied, modulo $998~244~353$ .
Formally, let $M = 998~244~353$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output the integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
Tenzing has $m$ conditions. Each condition has the form of $x_i+x_j\le 1$ or $x_i+x_j\ge 1$ .
Tenzing wants to know the probability that all the conditions are satisfied, modulo $998~244~353$ .
Formally, let $M = 998~244~353$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{p}{q}$ , where $p$ and $q$ are integers and $q \not \equiv 0 \pmod{M}$ . Output the integer equal to $p \cdot q^{-1} \bmod M$ . In other words, output the integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
输入格式
The first line contains two integers $n$ and $m$ ( $1\le n\le 20$ , $0\le m\le n^2+n$ ).
Then following $m$ lines of input contains three integers $t$ , $i$ and $j$ ( $t \in \{0,1\}$ , $1\le i\le j\le n$ ).
- If $t=0$ , the condition is $x_i+x_j\le 1$ .
- If $t=1$ , the condition is $x_i+x_j\ge 1$ .
It is guaranteed that all conditions are pairwise distinct.
Then following $m$ lines of input contains three integers $t$ , $i$ and $j$ ( $t \in \{0,1\}$ , $1\le i\le j\le n$ ).
- If $t=0$ , the condition is $x_i+x_j\le 1$ .
- If $t=1$ , the condition is $x_i+x_j\ge 1$ .
It is guaranteed that all conditions are pairwise distinct.
输出格式
Output the probability that all the conditions are satisfied, modulo $M = 998~244~353$ .
输入输出样例
输入 #1
3 2 0 1 2 1 3 3
输出 #1
748683265
输入 #2
3 3 0 1 2 0 1 3 0 2 3
输出 #2
748683265
输入 #3
3 4 0 1 2 0 1 3 1 2 3 1 2 2
输出 #3
935854081
输入 #4
4 4 0 1 2 0 3 4 1 1 3 1 2 4
输出 #4
0
输入 #5
8 12 0 1 2 0 2 3 1 3 4 0 1 4 0 5 6 0 6 7 1 7 8 0 5 8 1 3 7 1 3 8 1 4 7 1 4 8
输出 #5
997687297
In the first test case, the conditions are $x_1+x_2 \le 1$ and $x_3+x_3\ge 1$ , and the probability that each condition is satisfied is $\frac 12$ , so the probability that they are both satisfied is $\frac 12\cdot \frac 12=\frac 14$ , modulo $998~244~353$ is equal to $748683265$ .
In the second test case, the answer is $\frac 14$ .
In the third test case, the answer is $\frac 1{16}$ .
In the fourth test case, the sum of all variables must equal $2$ , so the probability is $0$ .
In the second test case, the answer is $\frac 14$ .
In the third test case, the answer is $\frac 1{16}$ .
In the fourth test case, the sum of all variables must equal $2$ , so the probability is $0$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted