QOJ.ac

QOJ

حد الوقت: 2.0 s حد الذاكرة: 1024 MB مجموع النقاط: 100

#15497. 奶油夹心核桃酥

الإحصائيات

Nuci Umplute cu Cremă(奶油夹心核桃酥)是一种非常美味的罗马尼亚甜点。核桃的“外壳”是由一种特殊的面团配方制成的,然后在特殊形状的烤箱中加热成型。

你想制作一些 Nuci。你祖母的配方上说制作过程非常简单。最关键的一步是准备 Nuci 的两半。为了制作出最完美的 Nuci,两半必须在不同的摄氏温度下加热。此外,这两个温度的绝对差必须是 $k$ 的倍数(这两个条件确保了奶油会由于对流而混合,从而刺激你的味蕾)。

这比看起来要难,因为这种特殊形状的烤箱很奇怪。为了设定温度,你必须输入数字 $n$ 的一个数位排列。这将作为温度。你输入的数字不能以 0 开头。

由于数字 $n$ 非常大,你决定编写一个程序来寻找任意一组满足条件的温度。

输入格式

第一行包含两个整数:$m$ 和 $k$($2 \le m \le 5 \cdot 10^6$,$2 \le k \le 5 \cdot 10^6$,$4 \le m \cdot k \le 10^7$)。

第二行包含一个 $m$ 位的整数 $n$,该整数不含前导零。

输出格式

如果无法找到满足条件的两个温度,输出 -1。否则,输出两行。

每行输出其中一个温度。这两个温度必须是 $n$ 的数位排列,不能有前导零,且必须互不相同。

样例

输入 1

6 3
123042

输出 1

102234
102243

输入 2

6 3
111111

输出 2

-1

说明

在第一个样例中,温度 $102234$ 和 $102243$ 都是 $123042$ 的数位排列。此外,$102243 - 102234 = 9 = 3 \cdot 3$。也存在其他可能的解。

在第二个样例中,$111111$ 只有一种唯一的数位排列。因此,无法选择两个不同的温度。

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.