CF1734E.Rectangular Congruence
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a prime number n , and an array of n integers b1,b2,…,bn , where 0≤bi<n for each 1≤i≤n .
You have to find a matrix a of size n×n such that all of the following requirements hold:
- 0≤ai,j<n for all 1≤i,j≤n .
- ar1,c1+ar2,c2≡ar1,c2+ar2,c1(modn) for all positive integers r1 , r2 , c1 , and c2 such that 1≤r1<r2≤n and 1≤c1<c2≤n .
- ai,i=bi for all 1≤i≤n .
Here x≡y(modm) denotes that x and y give different remainders when divided by m .
If there are multiple solutions, output any. It can be shown that such a matrix always exists under the given constraints.
输入格式
The first line contains a single positive integer n ( 2≤n<350 ).
The second line contains n integers b1,b2,…,bn ( 0≤bi<n ) — the required values on the main diagonal of the matrix.
It is guaranteed that n is prime.
输出格式
Print n lines. On the i -th line, print n integers ai,1,ai,2,…,ai,n , each separated with a space.
If there are multiple solutions, output any.
输入输出样例
输入#1
2 0 0
输出#1
0 1 0 0
输入#2
3 1 1 1
输出#2
1 2 2 1 1 0 1 0 1
输入#3
5 1 4 1 2 4
输出#3
1 0 1 3 4 1 4 3 1 0 2 4 1 0 2 1 2 2 2 2 2 2 0 1 4
说明/提示
In the first example, the answer is valid because all entries are non-negative integers less than n=2 , and a1,1+a2,2≡a1,2+a2,1(mod2) (because a1,1+a2,2=0+0≡0(mod2) and $a_{1,2}+a_{2,1} = 1 + 0 \equiv 1 \pmod 2 $ ). Moreover, the values on the main diagonals are equal to 0,0 as required.
In the second example, the answer is correct because all entries are non-negative integers less than n=3 , and the second condition is satisfied for all quadruplets (r1,r2,c1,c2) . For example:
- When r1=1 , r2=2 , c1=1 and c2=2 , a1,1+a2,2≡a1,2+a2,1(mod3) because a1,1+a2,2=1+1≡2(mod3) and $a_{1,2}+a_{2,1} = 2 + 1 \equiv 0 \pmod 3 $ .
- When r1=2 , r2=3 , c1=1 , and c2=3 , a2,1+a3,3≡a2,3+a3,1(mod3) because a2,1+a3,3=1+1≡2(mod3) and $a_{2,3}+a_{3,1} = 0 + 1 \equiv 1 \pmod 3 $ .
Moreover, the values on the main diagonal are equal to 1,1,1 as required.