A14324 | Bingo
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Getting ready for VK Fest 2021, you prepared a table with $n$ rows and $n$ columns, and filled each cell of this table with some event related with the festival that could either happen or not: for example, whether you will win a prize on the festival, or whether it will rain.
Forecasting algorithms used in VK have already estimated the probability for each event to happen. Event in row $i$ and column $j$ will happen with probability $a_{i, j} \cdot 10^{-4}$ . All of the events are mutually independent.
Let's call the table winning if there exists a line such that all $n$ events on it happen. The line could be any horizontal line (cells $(i, 1), (i, 2), \ldots, (i, n)$ for some $i$ ), any vertical line (cells $(1, j), (2, j), \ldots, (n, j)$ for some $j$ ), the main diagonal (cells $(1, 1), (2, 2), \ldots, (n, n)$ ), or the antidiagonal (cells $(1, n), (2, n - 1), \ldots, (n, 1)$ ).
Find the probability of your table to be winning, and output it modulo $31\,607$ (see Output section).
Forecasting algorithms used in VK have already estimated the probability for each event to happen. Event in row $i$ and column $j$ will happen with probability $a_{i, j} \cdot 10^{-4}$ . All of the events are mutually independent.
Let's call the table winning if there exists a line such that all $n$ events on it happen. The line could be any horizontal line (cells $(i, 1), (i, 2), \ldots, (i, n)$ for some $i$ ), any vertical line (cells $(1, j), (2, j), \ldots, (n, j)$ for some $j$ ), the main diagonal (cells $(1, 1), (2, 2), \ldots, (n, n)$ ), or the antidiagonal (cells $(1, n), (2, n - 1), \ldots, (n, 1)$ ).
Find the probability of your table to be winning, and output it modulo $31\,607$ (see Output section).
输入格式
The first line contains a single integer $n$ ( $2 \le n \le 21$ ) — the dimensions of the table.
The $i$ -th of the next $n$ lines contains $n$ integers $a_{i, 1}, a_{i, 2}, \ldots, a_{i, n}$ ( $0 < a_{i, j} < 10^4$ ). The probability of event in cell $(i, j)$ to happen is $a_{i, j} \cdot 10^{-4}$ .
The $i$ -th of the next $n$ lines contains $n$ integers $a_{i, 1}, a_{i, 2}, \ldots, a_{i, n}$ ( $0 < a_{i, j} < 10^4$ ). The probability of event in cell $(i, j)$ to happen is $a_{i, j} \cdot 10^{-4}$ .
输出格式
Print the probability that your table will be winning, modulo $31\,607$ .
Formally, let $M = 31\,607$ . 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 such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
Formally, let $M = 31\,607$ . 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 such an integer $x$ that $0 \le x < M$ and $x \cdot q \equiv p \pmod{M}$ .
输入输出样例
输入 #1
2 5000 5000 5000 5000
输出 #1
5927
输入 #2
2 2500 6000 3000 4000
输出 #2
24812
输入 #3
3 1000 2000 3000 4000 5000 6000 7000 8000 9000
输出 #3
25267
In the first example, any two events form a line, and the table will be winning if any two events happen. The probability of this is $\frac{11}{16}$ , and $5927 \cdot 16 \equiv 11 \pmod{31\,607}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted