CF1530F.Bingo
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai,j⋅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),…,(i,n) for some i ), any vertical line (cells (1,j),(2,j),…,(n,j) for some j ), the main diagonal (cells (1,1),(2,2),…,(n,n) ), or the antidiagonal (cells (1,n),(2,n−1),…,(n,1) ).
Find the probability of your table to be winning, and output it modulo 31607 (see Output section).
输入格式
The first line contains a single integer n ( 2≤n≤21 ) — the dimensions of the table.
The i -th of the next n lines contains n integers ai,1,ai,2,…,ai,n ( 0<ai,j<104 ). The probability of event in cell (i,j) to happen is ai,j⋅10−4 .
输出格式
Print the probability that your table will be winning, modulo 31607 .
Formally, let M=31607 . It can be shown that the answer can be expressed as an irreducible fraction qp , where p and q are integers and q≡0(modM) . Output the integer equal to p⋅q−1modM . In other words, output such an integer x that 0≤x<M and x⋅q≡p(modM) .
输入输出样例
输入#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 1611 , and 5927⋅16≡11(mod31607) .