CF510E.Fox And Dinner

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Fox Ciel is participating in a party in Prime Kingdom. There are n foxes there (include Fox Ciel). The i-th fox is a__i years old.

They will have dinner around some round tables. You want to distribute foxes such that:

  1. Each fox is sitting at some table.
  2. Each table has at least 3 foxes sitting around it.
  3. The sum of ages of any two adjacent foxes around each table should be a prime number.

If k foxes _f_1, _f_2, ..., f__k are sitting around table in clockwise order, then for 1 ≤ i ≤ k - 1: f__i and f__i + 1 are adjacent, and _f_1 and f__k are also adjacent.

If it is possible to distribute the foxes in the desired manner, find out a way to do that.

小狐狸雪儿正在参加“质数王国”举办的一场派对。现场共有 nn 只狐狸(包括雪儿本人)。第 ii 只狐狸的年龄为 aia_i 岁。

他们将围坐在若干张圆桌旁共进晚餐。你需要将狐狸们分配到各张圆桌上,使得满足以下条件:

  1. 每只狐狸恰好坐在某一张桌子上;
  2. 每张桌子周围至少坐有 3 只狐狸;
  3. 在每张桌子周围,任意两只相邻狐狸的年龄之和必须为质数。

若 kk 只狐狸 f1,f2,…,fkf_1, f_2, \dots, f_k 按顺时针顺序围坐在一张圆桌旁,则对所有 1≤i≤k−11 \le i \le k-1,fif_i 与 fi+1f_{i+1} 相邻;此外,f1f_1 与 fkf_k 也相邻。

如果能够以满足上述要求的方式分配狐狸,请给出一种可行方案。

输入格式

The first line contains single integer n (3 ≤ n ≤ 200): the number of foxes in this party.

The second line contains n integers a__i (2 ≤ a__i ≤ 104).

第一行包含一个整数 nn(3≤n≤2003 \leq n \leq 200):本次聚会中狐狸的数量。

第二行包含 nn 个整数 aia_i(2≤ai≤1042 \leq a_i \leq 10^4)。

输出格式

If it is impossible to do this, output "Impossible".

Otherwise, in the first line output an integer m (): the number of tables.

Then output m lines, each line should start with an integer k -=– the number of foxes around that table, and then k numbers — indices of fox sitting around that table in clockwise order.

If there are several possible arrangements, output any of them.

如果无法实现,则输出 “Impossible”。

否则,第一行输出一个整数 mm():表示桌子的数量。

随后输出 mm 行,每行首先输出一个整数 kk —— 表示围坐在该桌子旁的狐狸数量,然后输出 kk 个数字 —— 表示按顺时针顺序围坐于该桌子旁的狐狸的编号。

若存在多种可行方案,输出任意一种即可。

输入输出样例

  • 输入#1

    4
    3 4 8 9

    输出#1

    1
    4 1 2 4 3
  • 输入#2

    5
    2 2 2 2 2

    输出#2

    Impossible
  • 输入#3

    12
    2 3 4 5 6 7 8 9 10 11 12 13

    输出#3

    1
    12 1 2 3 6 5 12 9 8 7 10 11 4
  • 输入#4

    24
    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

    输出#4

    3
    6 1 2 3 6 5 4
    10 7 8 9 12 15 14 13 16 11 10
    8 17 18 23 22 19 20 21 24

说明/提示

In example 1, they can sit around one table, their ages are: 3-8-9-4, adjacent sums are: 11, 17, 13 and 7, all those integers are primes.

In example 2, it is not possible: the sum of 2+2 = 4 is not a prime number.

在示例 1 中,他们可以围坐在一张桌子旁,年龄分别为:3-8-9-4,相邻年龄之和为:11、17、13 和 7,这些整数均为素数。

在示例 2 中,这是不可能的:2 + 2 = 4 不是素数。

输入解题思路,AI测评打分。不知道怎么写?

首页