CF1734E.Rectangular Congruence

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

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 0≤bi<n0 \leq b_i \lt n for each 1≤i≤n1 \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:

  • 0≤ai,j<n0 \le a_{i,j} \lt n for all 1≤i,j≤n1 \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 1≤r1<r2≤n1 \le r_1 \lt r_2 \le n and 1≤c1<c2≤n1 \le c_1 \lt c_2 \le n.

  • ai,i=bia_{i,i} = b_i for all 1≤i≤n1 \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.

给你一个质数 nn 和一个由 nn 个整数组成的数组 b1,b2,…,bnb_1,b_2,\ldots, b_n,其中对每个 1≤i≤n1 \le i \leq n 均满足 0≤bi<n0 \leq b_i \lt n。

你需要构造一个大小为 n×nn \times n 的矩阵 aa,使得以下所有条件均成立:

  • 对所有 1≤i,j≤n1 \le i, j \le n,均有 0≤ai,j<n0 \le a_{i,j} \lt n。

  • 对所有满足 1≤r1<r2≤n1 \le r_1 \lt r_2 \le n 和 1≤c1<c2≤n1 \le c_1 \lt c_2 \le n 的正整数 r1r_1, r2r_2, c1c_1, c2c_2,均有

    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.

  • 对所有 1≤i≤n1 \le i \leq n,均有 ai,i=bia_{i,i} = b_i。

此处 x≢y(modm)x \not \equiv y \pmod m 表示 xx 与 yy 除以 mm 后所得余数不同。

若存在多个解,输出任意一个即可。可以证明:在给定约束下,这样的矩阵一定存在。

输入格式

The first line contains a single positive integer nn (2≤n<3502 \le n \lt 350).

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

It is guaranteed that nn is prime.

第一行包含一个正整数 nn(2≤n<3502 \le n \lt 350)。

第二行包含 nn 个整数 b1,b2,…,bnb_1, b_2, \ldots, b_n(0≤bi<n0 \le b_i \lt n)——即矩阵主对角线上所需的数值。

保证 nn 是质数。

输出格式

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.

输出 nn 行。在第 ii 行中,输出 nn 个整数 ai,1,ai,2,…,ai,na_{i, 1}, a_{i, 2}, \ldots, a_{i, n},各整数之间用空格分隔。

若存在多个解,输出任意一个即可。

输入输出样例

  • 输入#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+0≡0(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+1≡2(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+1≡2(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.

在第一个例子中,该答案是合法的,因为所有元素均为小于 n=2n = 2 的非负整数,且满足 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(因为 a1,1+a2,2=0+0≡0(mod2)a_{1,1}+a_{2,2} = 0 + 0 \equiv 0 \pmod 2,而 a1,2+a2,1=1+0≡1(mod2)a_{1,2}+a_{2,1} = 1 + 0 \equiv 1 \pmod 2)。此外,主对角线上的元素值为 0,00,0,符合要求。

在第二个例子中,该答案是正确的,因为所有元素均为小于 n=3n = 3 的非负整数,且对所有四元组 (r1,r2,c1,c2)(r_1, r_2, c_1, c_2) 均满足第二个条件。例如:

  • 当 r1=1r_1=1、r2=2r_2=2、c1=1c_1=1、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,因为 a1,1+a2,2=1+1≡2(mod3)a_{1,1}+a_{2,2} = 1 + 1 \equiv 2 \pmod 3,而 a1,2+a2,1=2+1≡0(mod3)a_{1,2}+a_{2,1} = 2 + 1 \equiv 0 \pmod 3。
  • 当 r1=2r_1=2、r2=3r_2=3、c1=1c_1=1、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,因为 a2,1+a3,3=1+1≡2(mod3)a_{2,1}+a_{3,3} = 1 + 1 \equiv 2 \pmod 3,而 a2,3+a3,1=0+1≡1(mod3)a_{2,3}+a_{3,1} = 0 + 1 \equiv 1 \pmod 3。

此外,主对角线上的元素值为 1,1,11,1,1,符合要求。

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

首页