QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 256 MB 總分: 100

#6715. 一个数组和更多的数组

统计

有 $k$ 个整数数组 $a_1, a_2, \dots, a_k$,其中第 $i$ 个数组包含 $l_i$ 个元素。令 $n = l_1 + l_2 + \dots + l_k$。

你需要找到 $k$ 个整数 $d_1, d_2, \dots, d_k$,使得所有数字 $(a_{i,j} + d_i)$ 两两不同,且满足 $1 \le a_{i,j} + d_i \le n$。

输入格式

第一行包含两个整数 $n$ 和 $k$ ($1 \le n \le 10^4, 1 \le k \le 5$),分别表示数组中元素的总数和数组的个数。

接下来的 $k$ 行包含这些数组。第 $i$ 行包含一个整数 $l_i$ ($1 \le l_i \le n$) 和 $l_i$ 个整数 $a_{i,1}, a_{i,2}, \dots, a_{i,l_i}$ ($1 \le a_{i,j} \le n$),分别表示第 $i$ 个数组的长度和元素。

保证 $n = l_1 + l_2 + \dots + l_k$。

输出格式

如果不存在满足要求的 $d$ 值,输出一行 “No”。

否则,第一行输出 “Yes”。 第二行输出 $k$ 个整数 $d_1, d_2, \dots, d_k$,即需要加到对应数组元素上的值,使得最终形成 $1$ 到 $n$ 的 $n$ 个不同整数。

如果存在多个正确答案,输出其中任意一个即可。

样例

样例输入 1

5 5
1 1
1 2
1 3
1 4
1 5

样例输出 1

Yes
0 0 0 0 0

样例输入 2

6 4
2 2 3
1 6
1 4
2 1 5

样例输出 2

Yes
1 -5 1 1

样例输入 3

7 2
4 1 4 5 6
3 1 2 6

样例输出 3

Yes
0 1

样例输入 4

4 2
2 2 3
2 2 4

样例输出 4

No

说明

在第一个样例中,$d = [0, 0, 0, 0, 0]$ 满足条件,因为加上对应值后,形成了数组 $[1], [2], [3], [4], [5]$。

在第二个样例中,$d = [1, -5, 1, 1]$ 满足条件,因为加上对应值后,形成了数组 $[3, 4], [1], [5], [2, 6]$。

在第三个样例中,$d = [0, 1]$ 满足条件,因为加上对应值后,形成了数组 $[1, 4, 5, 6]$ 和 $[2, 3, 7]$。

子任务

  1. (8 分): $k = 1$;
  2. (9 分): $a_{i,j} + 1 = a_{i,j+1}$,对于 $1 \le i \le k, 1 \le j < l_i$;
  3. (15 分): $k \le 2$;
  4. (21 分): $k \le 3$;
  5. (10 分): $a_{i,j} + 2 = a_{i,j+1}$,对于 $1 \le i \le k, 1 \le j < l_i$;
  6. (10 分): $(\max_{j \in [1; l_i]} a_{i,j}) - (\min_{j \in [1; l_i]} a_{i,j}) = (n - k)$,对于 $1 \le i \le k$;
  7. (10 分): $n \le 30$;
  8. (17 分): 无附加限制。

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.