CF1530F.Bingo

省选/NOI-

通过率:0%

时间限制:7.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Getting ready for VK Fest 2021, you prepared a table with nn rows and nn 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 ii and column jj will happen with probability ai,j⋅10−4a_{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 nn events on it happen. The line could be any horizontal line (cells (i,1),(i,2),…,(i,n)(i, 1), (i, 2), \ldots, (i, n) for some ii), any vertical line (cells (1,j),(2,j),…,(n,j)(1, j), (2, j), \ldots, (n, j) for some jj), the main diagonal (cells (1,1),(2,2),…,(n,n)(1, 1), (2, 2), \ldots, (n, n)), or the antidiagonal (cells (1,n),(2,n−1),…,(n,1)(1, n), (2, n - 1), \ldots, (n, 1)).

Find the probability of your table to be winning, and output it modulo 31 60731\,607 (see Output section).

为迎接 VK Fest 2021,你准备了一张 nn 行 nn 列的表格,并在每个格子中填入了一个与该节日相关的事件,该事件可能发生,也可能不发生:例如,你在节日期间是否获奖,或节日期间是否会下雨。

VK 中使用的预测算法已为每个事件的发生概率进行了估算。第 ii 行第 jj 列的事件发生的概率为 ai,j⋅10−4a_{i, j} \cdot 10^{-4}。所有事件相互独立。

若存在某条“线”,使得该线上全部 nn 个事件均发生,则称这张表为“获胜表”。此处的“线”可以是任意一条水平线(即对某个 ii,格子 (i,1),(i,2),…,(i,n)(i, 1), (i, 2), \ldots, (i, n)),任意一条竖直线(即对某个 jj,格子 (1,j),(2,j),…,(n,j)(1, j), (2, j), \ldots, (n, j)),主对角线(即格子 (1,1),(2,2),…,(n,n)(1, 1), (2, 2), \ldots, (n, n)),或副对角线(即格子 (1,n),(2,n−1),…,(n,1)(1, n), (2, n - 1), \ldots, (n, 1))。

请计算你的表格为“获胜表”的概率,并将结果对 31 60731\,607 取模后输出(参见“输出”部分)。

输入格式

The first line contains a single integer nn (2≤n≤212 \le n \le 21) — the dimensions of the table.

The ii-th of the next nn lines contains nn integers ai,1,ai,2,…,ai,na_{i, 1}, a_{i, 2}, \ldots, a_{i, n} (0<ai,j<1040 \lt a_{i, j} \lt 10^4). The probability of event in cell (i,j)(i, j) to happen is ai,j⋅10−4a_{i, j} \cdot 10^{-4}.

第一行包含一个整数 nn(2≤n≤212 \le n \le 21)—— 表格的维度。

接下来的 nn 行中,第 ii 行包含 nn 个整数 ai,1,ai,2,…,ai,na_{i, 1}, a_{i, 2}, \ldots, a_{i, n}(0<ai,j<1040 \lt a_{i, j} \lt 10^4)。单元格 (i,j)(i, j) 中事件发生的概率为 ai,j⋅10−4a_{i, j} \cdot 10^{-4}。

输出格式

Print the probability that your table will be winning, modulo 31 60731\,607.

Formally, let M=31 607M = 31\,607. It can be shown that the answer can be expressed as an irreducible fraction pq\frac{p}{q}, where pp and qq are integers and q≢0(modM)q \not \equiv 0 \pmod{M}. Output the integer equal to p⋅q−1 mod Mp \cdot q^{-1} \bmod M. In other words, output such an integer xx that 0≤x<M0 \le x \lt M and x⋅q≡p(modM)x \cdot q \equiv p \pmod{M}.

输出你的桌子获胜的概率,对 31 60731\,607 取模。

形式化地,令 M=31 607M = 31\,607。可以证明,答案可表示为既约分数 pq\frac{p}{q},其中 pp 和 qq 为整数,且 q≢0(modM)q \not \equiv 0 \pmod{M}。请输出整数 p⋅q−1 mod Mp \cdot q^{-1} \bmod M。换言之,请输出满足 0≤x<M0 \le x \lt M 且 x⋅q≡p(modM)x \cdot q \equiv p \pmod{M} 的整数 xx。

输入输出样例

  • 输入#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 1116\frac{11}{16}, and 5927⋅16≡11(mod31 607)5927 \cdot 16 \equiv 11 \pmod{31\,607}.

在第一个例子中,任意两个事件构成一条直线,当任意两个事件发生时,该表格即为获胜状态。该情况发生的概率为 1116\frac{11}{16},且 5927⋅16≡11(mod31 607)5927 \cdot 16 \equiv 11 \pmod{31\,607}。

输入解题思路,AI测评打分。不知道怎么写?

首页