QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 1024 MB Total points: 100

#16215. Constructing a matrix

Statistics

鲍勃有一个行数为 $n$,列数为 $n$ 的矩阵。每个位置上都有一个介于 $1$ 和 $n^2$ 之间的整数。鲍勃记得第 $i$($0\le i\le n-1$)行里有 $a_i$ 个不同数字,第 $i$($0\le i\le n-1$)列里有 $b_i$ 个不同数字。由于鲍勃不喜欢在整行或整列中重复相同的数字,所以 $a_i,b_i\ge 2$。

不知何故,鲍勃丢失了矩阵,现在只剩下$a$和$b$了。请帮助鲍勃恢复矩阵!任何满足给定 $a$ 和 $b$ 约束,且元素均介于 $1$ 到 $n^2$ 的矩阵都被认为是正确的。

Implementation Details

你应该包含 matrix.h,并实现如下过程:

int[][] cons(int n, int[] a, int[] b)

  • $n$: 矩阵的边长。
  • $a$: 每行的不同数个数。
  • $b$: 每列的不同数个数。
  • 你实现的过程会被调用恰好一次。
  • 你应该返回一个 $n\times n$ 的你构造的矩阵 $m$。第 $i$ 行第 $j$ 列的元素应为 $m[i][j]$。
  • 输入保证存在解。

Example

考虑如下调用:cons(3, [2, 2, 3], [2, 3, 3])

一个合法的返回矩阵为 [[1, 2, 1], [2, 3, 2], [1, 9, 4]]

Constraints

$1\le n\le 2000$。

对于每个 $1\le i\le n$,$2\le a_i,b_i\le n$。

输入保证有解。

Subtasks

  1. (10分)$n\le 5$
  2. (20分)$n\le 10$
  3. (20分)$n\le 50$
  4. (20分)对于每个 $i$,$b_i=2$。
  5. (30分)无特殊限制。

Sample Grader

样例交互器以下列格式读取输入。

  • 第一行:$n$
  • 第二行:$a[0]~a[1]~\cdots~a[n-1]$​
  • 第三行:$b[0]~b[1]~\cdots~b[n-1]$

样例交互器以下列格式打印你的输出。

  • 你构造的矩阵,每行之间用换行分割,每行内用空格分割

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.