QOJ.ac

QOJ

Time Limit: 1.5 s Memory Limit: 256 MB Total points: 100

#11568. Simple Task

Statistics

我们称一个非空正整数序列为 奇怪的,当且仅当其元素之和是一个质数。

给定一个长度为 $n$ 的数组 $a$,其由质数组成。同时给定一个整数 $k$。

将数组 $a$ 划分为 $k$ 个非空子序列$^1$,使得数组 $a$ 的每个元素恰好属于其中一个子序列,并且在得到的 $k$ 个子序列中,奇怪的子序列数量最少。

本题每个测试包含若干组输入数据。你需要对每一组输入数据独立求解。

注意本题不存在“没有额外限制”的部分。

输入格式

第一行包含一个整数 $T$ $(1\le T\le 10^5)$ —— 输入数据组数。

接下来是 $T$ 组输入数据的描述。

每组输入数据的第一行包含两个整数 $n$, $k$ $(1 \le k \le n \le 10^5)$ —— 数组 $a$ 的长度以及需要划分成的子序列个数。

第二行包含 $n$ 个质数 $a_1, a_2, \ldots, a_n$ $(2\le a_i\le 10^5, a_i\le a_{i+1})$ —— 数组 $a$ 的元素。

保证同一个测试中所有输入数据组的 $n$ 之和不超过 $10^5$。

输出格式

对于每组输入数据,按如下格式输出一种最优划分方案:

  • 第一行输出一个整数 $m$ —— 划分后得到的子序列中,奇怪的子序列个数;
  • 接下来 $k$ 行中,第 $i$ 行输出整数 $s_i$ 与 $b_1, b_2, \ldots, b_{s_i}$ $(1\le s_i\le n)$ —— 该子序列包含的元素个数以及这些元素本身。

子序列的输出顺序以及子序列内部元素的输出顺序均不作要求。

若存在多种正确答案,输出任意一种均可。

说明

$^1$ 若能从数组 $b$ 中删除若干元素(也可以一个都不删)得到序列 $c$,则称序列 $c$ 是数组 $b$ 的一个子序列。

样例数据

输入

4
3 1
5 5 13
4 2
2 3 5 7
5 3
3 3 5 5 13
6 5
2 2 2 3 3 3

输出

1
3 13 5 5
0
2 2 7
2 3 5
1
1 13
2 3 3
2 5 5
4
1 2
1 2
1 2
1 3
2 3 3

子任务

  1. ($2$ 分):$T \leq 20$,$k=1$;
  2. ($5$ 分):$n \leq 4$,$a_i \leq 10^4$($1\le i\le n$);
  3. ($8$ 分):$T \leq 20$,$n \leq 10$,$a_i \leq 10^4$;
  4. ($4$ 分):$n$ 为偶数,且对所有 $1\le i\le n$ 有 $a_i > 2$;
  5. ($18$ 分):$n$ 为奇数,且对所有 $1\le i\le n$ 有 $a_i > 2$;
  6. ($10$ 分):$2\cdot k \ge n + 1$;
  7. ($29$ 分):$n$ 为偶数;
  8. ($24$ 分):$n$ 为奇数。

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.