CF2249D.Xor Permutation Matrix
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given two integers n and x (0≤x≤n−1).
Construct a matrix A of size n×n satisfying all of the following conditions:
-
For every 1≤i,j≤n, 0≤Ai,j≤n−1;
-
Every row in A forms a permutation of 0,1,…,n−1;
-
Every column in A forms a permutation of 0,1,…,n−1;
-
For every 1≤i,j≤n−1, $$ A_{i,j} \oplus A_{i+1,j} \oplus A_{i,j+1} \oplus A_{i+1,j+1} = x. $$
Here, ⊕ denotes the bitwise XOR operation.
Or determine that no such matrix exists.
给你两个整数 n 和 x(满足 0≤x≤n−1)。
请构造一个大小为 n×n 的矩阵 A,使其满足以下所有条件:
- 对于每个 1≤i,j≤n,有 0≤Ai,j≤n−1;
- 矩阵 A 的每一行都是 0,1,…,n−1 的一个排列;
- 矩阵 A 的每一列都是 0,1,…,n−1 的一个排列;
- 对于每个 1≤i,j≤n−1,满足
Ai,j⊕Ai+1,j⊕Ai,j+1⊕Ai+1,j+1=x.
其中,⊕ 表示按位异或运算。
或者判定这样的矩阵不存在。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤180). The description of the test cases follows.
The only line of each test case contains two integers n and x (2≤n≤2500, 0≤x<n).
It is guaranteed that the sum of n over all test cases does not exceed 2500.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤180)。随后是各测试用例的描述。
每个测试用例仅一行,包含两个整数 n 和 x(2≤n≤2500,0≤x<n)。
保证所有测试用例的 n 之和不超过 2500。
输出格式
For each test case, output −1 if no such matrix exists. Otherwise, output any valid n lines of the matrix.
If several valid matrices exist, you may output any of them.
对于每个测试用例,若不存在满足条件的矩阵,则输出 −1;否则,输出该矩阵的任意一个有效解(共 n 行)。
若存在多个有效矩阵,可输出其中任意一个。
输入输出样例
输入#1
5 2 0 2 1 3 0 4 1 4 0
输出#1
0 1 1 0 -1 -1 0 2 1 3 2 1 3 0 1 3 0 2 3 0 2 1 0 1 2 3 1 0 3 2 2 3 0 1 3 2 1 0
说明/提示
In the first test case, the displayed matrix has both rows and columns equal to permutations of 0,1, and its only adjacent 2×2 submatrix has XOR 0.
The second and third test cases are impossible. In the last two test cases, every adjacent 2×2 submatrix has XOR, respectively, 1 and 0.
在第一个测试用例中,所显示的矩阵的每一行和每一列均为 0,1 的排列,且其唯一的相邻 2×2 子矩阵的异或值为 0。
第二个和第三个测试用例不可能实现。在最后两个测试用例中,每个相邻的 2×2 子矩阵的异或值分别为 1 和 0。
输入解题思路,AI测评打分。不知道怎么写?