QOJ.ac

QOJ

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

#4705. 化无序为有序

Statistiques

数字序列通常代表一个数值,但我们可以定义一种替代的解释方式。在本题中,我们定义了一种新的解释方式,并在此基础上定义了相同长度数字序列之间的顺序关系 $\prec$。

令 $s$ 为一个由 $n$ 个数字组成的序列 $d_1d_2 \dots d_n$,其中每个 $d_i$ ($1 \le i \le n$) 均为 $0, 1, \dots, 9$ 中的一个。 令 $\text{sum}(s)$、$\text{prod}(s)$ 和 $\text{int}(s)$ 定义如下:

$$\text{sum}(s) = d_1 + d_2 + \dots + d_n$$ $$\text{prod}(s) = (d_1 + 1) \times (d_2 + 1) \times \dots \times (d_n + 1)$$ $$\text{int}(s) = d_1 \times 10^{n-1} + d_2 \times 10^{n-2} + \dots + d_n \times 10^0$$

$\text{int}(s)$ 是数字序列 $s$ 按常规十进制解释所代表的整数。

令 $s_1$ 和 $s_2$ 为两个长度相同的数字序列。当且仅当满足以下条件之一时,称 $s_1 \prec s_2$(即 $s_1$ 小于 $s_2$):

  1. $\text{sum}(s_1) < \text{sum}(s_2)$
  2. $\text{sum}(s_1) = \text{sum}(s_2)$ 且 $\text{prod}(s_1) < \text{prod}(s_2)$
  3. $\text{sum}(s_1) = \text{sum}(s_2)$,$\text{prod}(s_1) = \text{prod}(s_2)$ 且 $\text{int}(s_1) < \text{int}(s_2)$

例如,对于 2 位数字序列,满足以下顺序关系:

$$00 \prec 01 \prec 10 \prec 02 \prec 20 \prec 11 \prec 03 \prec 30 \prec 12 \prec 21 \prec \dots \prec 89 \prec 98 \prec 99$$

你的任务是:给定一个 $n$ 位数字序列 $s$,计算在上述定义的顺序 $\prec$ 下,有多少个 $n$ 位数字序列小于 $s$。

输入格式

输入由单行上的单个测试用例组成。

$d_1d_2 \dots d_n$

$n$ 是一个正整数,且不超过 14。每个 $d_1, d_2, \dots, d_n$ 均为数字。

输出格式

输出在上述定义的顺序下,小于 $d_1d_2 \dots d_n$ 的 $n$ 位数字序列的数量。

样例

样例输入 1

20

样例输出 1

4

样例输入 2

020

样例输出 2

5

样例输入 3

118

样例输出 3

245

样例输入 4

11111111111111

样例输出 4

40073759

样例输入 5

99777222222211

样例输出 5

23733362467675

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.