A16401 | Construct Matrix
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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$ .
- 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$ .
输入格式
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$ .
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$ .
输出格式
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.
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.
输入输出样例
输入 #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 $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.
- 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.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted