CF1734E.Rectangular Congruence

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a prime number nn , and an array of nn integers b1,b2,,bnb_1,b_2,\ldots, b_n , where 0bi<n0 \leq b_i < n for each 1in1 \le i \leq n .

You have to find a matrix aa of size n×nn \times n such that all of the following requirements hold:

  • 0ai,j<n0 \le a_{i,j} < n for all 1i,jn1 \le i, j \le n .
  • ar1,c1+ar2,c2≢ar1,c2+ar2,c1(modn)a_{r_1, c_1} + a_{r_2, c_2} \not\equiv a_{r_1, c_2} + a_{r_2, c_1} \pmod n for all positive integers r1r_1 , r2r_2 , c1c_1 , and c2c_2 such that 1r1<r2n1 \le r_1 < r_2 \le n and 1c1<c2n1 \le c_1 < c_2 \le n .
  • ai,i=bia_{i,i} = b_i for all 1in1 \le i \leq n .

Here x≢y(modm)x \not \equiv y \pmod m denotes that xx and yy give different remainders when divided by mm .

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 nn ( 2n<3502 \le n < 350 ).

The second line contains nn integers b1,b2,,bnb_1, b_2, \ldots, b_n ( 0bi<n0 \le b_i < n ) — the required values on the main diagonal of the matrix.

It is guaranteed that nn is prime.

输出格式

Print nn lines. On the ii -th line, print nn integers ai,1,ai,2,,ai,na_{i, 1}, a_{i, 2}, \ldots, a_{i, 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=2n = 2 , and a1,1+a2,2≢a1,2+a2,1(mod2)a_{1,1}+a_{2,2} \not\equiv a_{1,2}+a_{2,1} \pmod 2 (because a1,1+a2,2=0+00(mod2)a_{1,1}+a_{2,2} = 0 + 0 \equiv 0 \pmod 2 and $a_{1,2}+a_{2,1} = 1 + 0 \equiv 1 \pmod 2 $ ). Moreover, the values on the main diagonals are equal to 0,00,0 as required.

In the second example, the answer is correct because all entries are non-negative integers less than n=3n = 3 , and the second condition is satisfied for all quadruplets (r1,r2,c1,c2)(r_1, r_2, c_1, c_2) . For example:

  • When r1=1r_1=1 , r2=2r_2=2 , c1=1c_1=1 and c2=2c_2=2 , a1,1+a2,2≢a1,2+a2,1(mod3)a_{1,1}+a_{2,2} \not\equiv a_{1,2}+a_{2,1} \pmod 3 because a1,1+a2,2=1+12(mod3)a_{1,1}+a_{2,2} = 1 + 1 \equiv 2 \pmod 3 and $a_{1,2}+a_{2,1} = 2 + 1 \equiv 0 \pmod 3 $ .
  • When r1=2r_1=2 , r2=3r_2=3 , c1=1c_1=1 , and c2=3c_2=3 , a2,1+a3,3≢a2,3+a3,1(mod3)a_{2,1}+a_{3,3} \not\equiv a_{2,3}+a_{3,1} \pmod 3 because a2,1+a3,3=1+12(mod3)a_{2,1}+a_{3,3} = 1 + 1 \equiv 2 \pmod 3 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,11,1,1 as required.

首页