Codeforces Round #822 (Div. 2) - E. Rectangular Congruence

同余

Problem - E - Codeforces

题意

给一个长度为 \(n(2<=n<350)\) 的数组 \(b_i\), \(0<=b_0,b_1...b_n<n\)

要构造一个大小为 \(n*n\) 的矩阵 A,\(a_{i,i}=b_i\), 并且满足对于任意的 \(0<=r_1<r_2<n,0<=c_1<c2<n\), 有 \(A_{r_1,c_1}+A_{r_2,c_2}\not\equiv A_{r_1,c_2}+A_{r_2,c_1}\pmod n\)

即任意一个子矩阵,满足在模 n 意义下,左上角 + 右下角 != 左下角 + 右上角

思路

可以将上述限制移项,得到 \(A_{r_1,c_1}-A_{r_1,c_2}\not\equiv A_{r_2,c_1}-A_{r_2,c_2}\pmod n\)

即对于任意一个子矩阵,在模 n 意义下,左上角 - 右上角 != 左下角 - 右下角

因此只需要让每一行为公差不同的等差数列即可

代码

#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
#define endl "\n"

typedef long long ll;
typedef pair<int, int> PII;

const int N = 360;
int a[N][N];
int n;
int b[N];

void print()
{
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			cout << a[i][j] << " ";
		cout << endl;
	}
}
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			a[i][j] = (j - i) * i + b[i];
			a[i][j] = (a[i][j] % n + n) % n;
		}
	}
	print();
    return 0;
}
posted @ 2022-09-26 22:27  hzy0227  阅读(27)  评论(0编辑  收藏  举报