CF1734E.Rectangular Congruence
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
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.
给你一个质数 n 和一个由 n 个整数组成的数组 b1,b2,…,bn,其中对每个 1≤i≤n 均满足 0≤bi<n。
你需要构造一个大小为 n×n 的矩阵 a,使得以下所有条件均成立:
-
对所有 1≤i,j≤n,均有 0≤ai,j<n。
-
对所有满足 1≤r1<r2≤n 和 1≤c1<c2≤n 的正整数 r1, r2, c1, c2,均有
ar1,c1+ar2,c2≡ar1,c2+ar2,c1(modn).
-
对所有 1≤i≤n,均有 ai,i=bi。
此处 x≡y(modm) 表示 x 与 y 除以 m 后所得余数不同。
若存在多个解,输出任意一个即可。可以证明:在给定约束下,这样的矩阵一定存在。
输入格式
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.
第一行包含一个正整数 n(2≤n<350)。
第二行包含 n 个整数 b1,b2,…,bn(0≤bi<n)——即矩阵主对角线上所需的数值。
保证 n 是质数。
输出格式
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.
输出 n 行。在第 i 行中,输出 n 个整数 ai,1,ai,2,…,ai,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=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.
在第一个例子中,该答案是合法的,因为所有元素均为小于 n=2 的非负整数,且满足 a1,1+a2,2≡a1,2+a2,1(mod2)(因为 a1,1+a2,2=0+0≡0(mod2),而 a1,2+a2,1=1+0≡1(mod2))。此外,主对角线上的元素值为 0,0,符合要求。
在第二个例子中,该答案是正确的,因为所有元素均为小于 n=3 的非负整数,且对所有四元组 (r1,r2,c1,c2) 均满足第二个条件。例如:
- 当 r1=1、r2=2、c1=1、c2=2 时,有 a1,1+a2,2≡a1,2+a2,1(mod3),因为 a1,1+a2,2=1+1≡2(mod3),而 a1,2+a2,1=2+1≡0(mod3)。
- 当 r1=2、r2=3、c1=1、c2=3 时,有 a2,1+a3,3≡a2,3+a3,1(mod3),因为 a2,1+a3,3=1+1≡2(mod3),而 a2,3+a3,1=0+1≡1(mod3)。
此外,主对角线上的元素值为 1,1,1,符合要求。
输入解题思路,AI测评打分。不知道怎么写?