CF1917E.Construct Matrix

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given an even integer nn and an integer kk. Your task is to construct a matrix of size n×nn \times n consisting of numbers 00 and 11 in such a way that the following conditions are true, or report that it is impossible:

  • the sum of all the numbers in the matrix is exactly kk;
  • the bitwise XOR\texttt{XOR} of all the numbers in the row ii is the same for each ii;
  • the bitwise XOR\texttt{XOR} of all the numbers in the column jj is the same for each jj.

给你一个偶数 nn 和一个整数 kk。你的任务是构造一个大小为 n×nn \times n 的、仅由数字 00 和 11 组成的矩阵,使其满足以下条件;若无法满足,则报告不可能:

  • 矩阵中所有数字之和恰好为 kk;
  • 每行 ii 中所有数字的按位 XOR\texttt{XOR} 值均相同;
  • 每列 jj 中所有数字的按位 XOR\texttt{XOR} 值均相同。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤1301 \leq t \leq 130) — the number of test cases. The description of the test cases follows.

Each test case is described by a single line, which contains two integers nn and kk (2≤n≤10002 \leq n \leq 1000, nn is even, 0≤k≤n20 \leq k \leq n^2).

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

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤1301 \leq t \leq 130),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例由一行描述,该行包含两个整数 nn 和 kk(2≤n≤10002 \leq n \leq 1000,nn 为偶数,0≤k≤n20 \leq k \leq n^2)。

保证所有测试用例中 nn 的总和不超过 20002000。

输出格式

For each test case, output Yes\texttt{Yes} if it's possible to construct a matrix that satisfies all of the problem's conditions, and No\texttt{No} otherwise.

If it is possible to construct a matrix, the ii-th of the next nn lines should contain nn integers representing the elements in the ii-th row of the matrix.

对于每个测试用例,如果能够构造出满足题目所有条件的矩阵,则输出 Yes\texttt{Yes};否则输出 No\texttt{No}。

如果可以构造出这样的矩阵,则接下来的 nn 行中,第 ii 行应包含 nn 个整数,表示该矩阵第 ii 行的元素。

输入输出样例

  • 输入#1

    5
    4 0
    6 6
    6 5
    4 2
    6 36

    输出#1

    Yes
    0 0 0 0
    0 0 0 0
    0 0 0 0
    0 0 0 0
    Yes
    1 0 0 0 0 0
    0 1 0 0 0 0
    0 0 1 0 0 0
    0 0 0 1 0 0
    0 0 0 0 1 0
    0 0 0 0 0 1
    No
    No
    Yes
    1 1 1 1 1 1
    1 1 1 1 1 1
    1 1 1 1 1 1
    1 1 1 1 1 1
    1 1 1 1 1 1
    1 1 1 1 1 1

说明/提示

In the first example, all conditions are satisfied:

  • the sum of all the numbers in the matrix is exactly 00;
  • the bitwise XOR\texttt{XOR} of all the numbers in the row ii is 00 for each ii;
  • the bitwise XOR\texttt{XOR} of all the numbers in the column jj is 00 for each jj.

In the third example, it can be shown that it's impossible to find a matrix satisfying all the problem's conditions.

在第一个例子中,所有条件均满足:

  • 矩阵中所有数字的和恰好为 00;
  • 对每个行 ii,该行中所有数字的按位 XOR\texttt{XOR} 值为 00;
  • 对每个列 jj,该列中所有数字的按位 XOR\texttt{XOR} 值为 00。

在第三个例子中,可以证明不存在满足本题所有条件的矩阵。

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

首页