CF2249D.Xor Permutation Matrix

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are given two integers nn and xx (0≤x≤n−10 \le x \le n-1).

Construct a matrix AA of size n×nn\times n satisfying all of the following conditions:

  • For every 1≤i,j≤n1 \le i, j \le n, 0≤Ai,j≤n−10 \le A_{i,j}\le n-1;

  • Every row in AA forms a permutation of 0,1,…,n−10, 1, \ldots, n-1;

  • Every column in AA forms a permutation of 0,1,…,n−10, 1, \ldots, n-1;

  • For every 1≤i,j≤n−11 \le i, j\le n-1, $$ A_{i,j} \oplus A_{i+1,j} \oplus A_{i,j+1} \oplus A_{i+1,j+1} = x. $$

    Here, ⊕\oplus denotes the bitwise XOR operation.

Or determine that no such matrix exists.

给你两个整数 nn 和 xx(满足 0≤x≤n−10 \le x \le n-1)。

请构造一个大小为 n×nn\times n 的矩阵 AA,使其满足以下所有条件:

  • 对于每个 1≤i,j≤n1 \le i, j \le n,有 0≤Ai,j≤n−10 \le A_{i,j}\le n-1;
  • 矩阵 AA 的每一行都是 0,1,…,n−10, 1, \ldots, n-1 的一个排列;
  • 矩阵 AA 的每一列都是 0,1,…,n−10, 1, \ldots, n-1 的一个排列;
  • 对于每个 1≤i,j≤n−11 \le i, j\le n-1,满足

    Ai,j⊕Ai+1,j⊕Ai,j+1⊕Ai+1,j+1=x.A_{i,j} \oplus A_{i+1,j} \oplus A_{i,j+1} \oplus A_{i+1,j+1} = x.

    其中,⊕\oplus 表示按位异或运算。

或者判定这样的矩阵不存在。

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1801 \le t \le 180). The description of the test cases follows.

The only line of each test case contains two integers nn and xx (2≤n≤25002\le n\le 2500, 0≤x<n0\le x \lt n).

It is guaranteed that the sum of nn over all test cases does not exceed 25002500.

每个测试包含多个测试用例。第一行包含测试用例的数量 tt(1≤t≤1801 \le t \le 180)。随后是各测试用例的描述。

每个测试用例仅一行,包含两个整数 nn 和 xx(2≤n≤25002\le n\le 2500,0≤x<n0\le x \lt n)。

保证所有测试用例的 nn 之和不超过 25002500。

输出格式

For each test case, output −1-1 if no such matrix exists. Otherwise, output any valid nn lines of the matrix.

If several valid matrices exist, you may output any of them.

对于每个测试用例,若不存在满足条件的矩阵,则输出 −1-1;否则,输出该矩阵的任意一个有效解(共 nn 行)。

若存在多个有效矩阵,可输出其中任意一个。

输入输出样例

  • 输入#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,10,1, and its only adjacent 2×22\times2 submatrix has XOR 00.

The second and third test cases are impossible. In the last two test cases, every adjacent 2×22\times2 submatrix has XOR, respectively, 11 and 00.

在第一个测试用例中,所显示的矩阵的每一行和每一列均为 0,10,1 的排列,且其唯一的相邻 2×22\times2 子矩阵的异或值为 00。

第二个和第三个测试用例不可能实现。在最后两个测试用例中,每个相邻的 2×22\times2 子矩阵的异或值分别为 11 和 00。

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

首页