QOJ.ac

QOJ

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

#4501. GREAT + SWERC = PORTO

Statistiques

我们希望今年在波尔图举办一场伟大的 SWERC,为此我们尝试了多种挑战方式。我们甚至将其构思为一个单词加法问题,类似于经典的 SEND+MORE=MONEY,其中每个字母代表一个数字($0, 1, 2, \dots, 8, 9$),使得算术运算成立。在单词加法中,不同的字母不能被分配相同的数字,且单词的首字母不能为零($0$)。特别地,单字母项不能为零。

为了解决这个单词加法问题,我们需要为 G、S 和 P 找到正整数,并为 R、E、A、T、W、C、O 找到对应的数字,使得每个字母都有不同的数字且求和正确。事实证明,与只有唯一解的经典问题 SEND+MORE=MONEY 不同,GREAT+SWERC=PORTO 有六个解。

T=7, E=3, W=9, G=1, A=0, P=4, S=2, C=8, R=6, O=5 T=7, E=3, W=9, G=2, A=0, P=4, S=1, C=8, R=6, O=5 T=8, E=5, W=1, G=3, A=7, P=9, S=6, C=4, R=0, O=2 T=8, E=5, W=1, G=6, A=7, P=9, S=3, C=4, R=0, O=2 T=9, E=5, W=2, G=1, A=8, P=7, S=6, C=4, R=0, O=3 T=9, E=5, W=2, G=6, A=8, P=7, S=1, C=4, R=0, O=3

拥有多个解并不会使 GREAT+SWERC=PORTO 成为一个好的手工题目,但对于程序员来说这依然是小菜一碟。此外,这也给了我们明年再次举办 SWERC 的理由,谁知道呢,未来几年或许也是如此!

任务

给定一个单词加法问题,计算其解的数量(可能为零)。

输入格式

第一行包含一个整数 $n$,随后有 $n$ 行,每行包含一个单词,单词最大长度为 $10$ 个字母。前 $n-1$ 个单词是要相加的项,最后一行是结果。

单词仅包含大写字母。如果单词长度不同,必须将其视为右对齐。例如,在 SEND+MORE=MONEY 问题中,第一个单词的 D 和第二个单词的 E 与最终单词的 Y 对齐。你还可以假设最后一个单词的长度大于或等于前面单词的最大长度,并且一个单词问题中最多涉及十个不同的字母。

数据范围

$3 \le n \le 10$ 每个单词最多有 $10$ 个符号(大写字母)。 一个单词问题最多涉及 $10$ 个不同的字母。

输出格式

输出一行,包含一个整数:给定单词加法问题的解的数量。

样例

输入格式 1

3
GREAT
SWERC
PORTO

输出格式 1

6

输入格式 2

3
SEND
MORE
MONEY

输出格式 2

1

输入格式 3

5
TOO
GOOD
TO
BE
TRUE

输出格式 3

93

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.