QOJ.ac

QOJ

시간 제한: 2.0 s 메모리 제한: 1024 MB 총점: 100 해킹 가능 ✓

#15474. 泡泡药水难题

통계

在 Bubbleland 宏伟的炼金实验室中,巫师们最受推崇的比赛之一就是魔药制作艺术。巫师们的目标是制作出最完美、最精炼的魔药,但有一个转折——每种魔药最初都是由 $N$ 种成分组成的混合物,他们的目标是将这些成分结合并简化为尽可能小的精华。

巫师们发现了一种神奇的操作,可以对他们的混合物重复执行。每种成分都由一个特殊数字中的一位数字表示。给你这个混合物,它是一个 $N$ 位数,操作如下:

选择混合物成分列表中的任意两个位置 $i$ 和 $j$。设 $A_i$ 和 $A_j$ 分别表示这些位置上的数字(成分)。你可以将 $A_i$ 和 $A_j$ 都替换为 $(A_i + A_j) \bmod 10$ 的结果。有趣的是,你甚至可以为 $i$ 和 $j$ 选择相同的下标,从而有效地将单个数字 $A_i$ 转化为 $(A_i + A_i) \bmod 10$。

通过这种强大的转变,巫师们可以一次又一次地精炼他们的魔药。他们的终极目标是产生通过任意次数的变换所能得到的最小的魔药混合物数字。

你作为一名经验丰富的魔药大师,必须确定通过对初始的 $N$ 位数执行任意次数的该操作,所能创建的最小可能数字。

输入格式

第一行包含一个整数 $N$:初始魔药混合物中的数字位数($1 \le N \le 10^6$)。

第二行包含一个长度为 $N$ 的由数字 0 到 9 组成的字符串,表示该 $N$ 位魔药混合物。第一位数字非零。

输出格式

输出一个长度为 $N$ 的字符串,表示在应用任意次数的变换操作后,所能得到的最小可能魔药混合物数字。结果可能包含前导零。

样例

输入样例 1

1
9

输出样例 1

2

输入样例 2

2
37

输出样例 2

00

说明

在第一个样例中,我们唯一能做的操作就是选择将我们拥有的单个数字翻倍。这样做,我们将从 9 变为 8 再变为 6 再变为 2,可以证明 2 是我们能达到的最小值。

在第二个样例中,我们可以选择对数字的第一位和第二位进行操作,将它们都转化为 $(3 + 7) \bmod 10 = 0$。

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.