Codeforces Round 917 (Div. 2)
E
Construct Matrix
Codeforces
2500
原题
← DF →
翻译中…

You are given an even integer $n$ and an integer $k$. Your task is to construct a matrix of size $n \times n$ consisting of numbers $0$ and $1$ 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 $k$;
  • the bitwise $\texttt{XOR}$ of all the numbers in the row $i$ is the same for each $i$;
  • the bitwise $\texttt{XOR}$ of all the numbers in the column $j$ is the same for each $j$.
翻译中…

Input

翻译中…

Each test consists of multiple test cases. The first line contains a single integer $t$ ($1 \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 $n$ and $k$ ($2 \leq n \leq 1000$, $n$ is even, $0 \leq k \leq n^2$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $2000$.

翻译中…

Output

翻译中…

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

翻译中…

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

翻译中…

Note

翻译中…

In the first example, all conditions are satisfied:

翻译中…
  • the sum of all the numbers in the matrix is exactly $0$;
  • the bitwise $\texttt{XOR}$ of all the numbers in the row $i$ is $0$ for each $i$;
  • the bitwise $\texttt{XOR}$ of all the numbers in the column $j$ is $0$ for each $j$.
翻译中…

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

翻译中…

样例

Input #1
5
4 0
6 6
6 5
4 2
6 36
Output #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
InputCopy OutputCopy
题目信息
题号
1917E
时间限制
1 s
内存限制
256 MB
标签
构造
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。