QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 512 MB Points totaux : 100

#1665. 数字

Statistiques

Diana 喜欢玩数字游戏。她有 $n$ 张卡片,每张卡片上写着一个正整数 $a_i$。 她闲暇时喜欢将卡片上的数字相乘。她会选择一个非空的卡片子集,并将这些卡片上的所有数字 $a_i$ 相乘。

当乘积的末位数字等于她最喜欢的数字 $d$ 时,Diana 就会感到高兴。现在她很好奇,应该选择哪些卡片,才能使乘积尽可能大,且乘积的末位数字为 $d$。请帮帮她。

输入格式

第一行包含整数 $n$ 和 $d$ ($1 \le n \le 10^5$, $0 \le d \le 9$)。第二行包含 $n$ 个整数 $a_i$ ($1 \le a_i \le 1000$)。

输出格式

在第一行,输出所选卡片的数量 $k$ ($1 \le k \le n$)。在下一行,以任意顺序输出所选卡片上的数字。 如果无法选择一个乘积末位数字为 $d$ 的卡片子集,则输出一行 $-1$。

样例

输入 1

6 4
4 11 8 2 1 13

输出 1

5
1 2 4 11 13

输入 2

3 1
2 4 6

输出 2

-1

输入 3

5 7
1 3 1 5 3

输出 3

-1

输入 4

6 3
8 9 4 17 11 5

输出 4

3
9 11 17

输入 5

5 6
2 2 2 2 2

输出 5

4
2 2 2 2

说明

在第一个样例中,$1 \times 2 \times 4 \times 11 \times 13 = 1144$,这是末位数字为 4 的最大乘积。去掉数字 1 后的同一组卡片也是一个有效的答案,同样,包含或不包含 1 的 8、11 和 13 的组合乘积也为 1144。

在第二个样例中,所有卡片上的数字都是偶数,它们的乘积不可能以奇数 1 结尾。

在第三个样例中,所有可能的乘积为 1、3、5、9、15 和 45,没有一个以数字 7 结尾。

在第四个样例中,$9 \times 11 \times 17 = 1683$,其末位数字为 3。

在第五个样例中,$2 \times 2 \times 2 \times 2 = 16$,其末位数字为 6。

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.