CF1142D.Foreigner

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Traveling around the world you noticed that many shop owners raise prices to inadequate values if the see you are a foreigner.

You define inadequate numbers as follows:

  • all integers from 11 to 99 are inadequate;
  • for an integer x≥10x \ge 10 to be inadequate, it is required that the integer ⌊x/10⌋\lfloor x / 10 \rfloor is inadequate, but that's not the only condition. Let's sort all the inadequate integers. Let ⌊x/10⌋\lfloor x / 10 \rfloor have number kk in this order. Then, the integer xx is inadequate only if the last digit of xx is strictly less than the reminder of division of kk by 1111.

Here ⌊x/10⌋\lfloor x / 10 \rfloor denotes x/10x/10 rounded down.

Thus, if xx is the mm-th in increasing order inadequate number, and mm gives the remainder cc when divided by 1111, then integers 10⋅x+0,10⋅x+1…,10⋅x+(c−1)10 \cdot x + 0, 10 \cdot x + 1 \ldots, 10 \cdot x + (c - 1) are inadequate, while integers 10⋅x+c,10⋅x+(c+1),…,10⋅x+910 \cdot x + c, 10 \cdot x + (c + 1), \ldots, 10 \cdot x + 9 are not inadequate.

The first several inadequate integers are 1,2,3,4,5,6,7,8,9,10,20,21,30,31,32…1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 30, 31, 32 \ldots. After that, since 44 is the fourth inadequate integer, 40,41,42,4340, 41, 42, 43 are inadequate, while 44,45,46,…,4944, 45, 46, \ldots, 49 are not inadequate; since 1010 is the 1010-th inadequate number, integers 100,101,102,…,109100, 101, 102, \ldots, 109 are all inadequate. And since 2020 is the 1111-th inadequate number, none of 200,201,202,…,209200, 201, 202, \ldots, 209 is inadequate.

You wrote down all the prices you have seen in a trip. Unfortunately, all integers got concatenated in one large digit string ss and you lost the bounds between the neighboring integers. You are now interested in the number of substrings of the resulting string that form an inadequate number. If a substring appears more than once at different positions, all its appearances are counted separately.

环游世界时,你注意到许多店主在发现你是外国人时,会将商品价格抬高至“不恰当的数值”。

你将“不恰当数”定义如下:

  • 所有从 11 到 99 的整数均为不恰当数;
  • 对于整数 x≥10x \ge 10,若其为不恰当数,则首先要求 ⌊x/10⌋\lfloor x / 10 \rfloor 是不恰当数;但这并非唯一条件。我们将所有不恰当数按升序排列。设 ⌊x/10⌋\lfloor x / 10 \rfloor 在该序列中排第 kk 位。那么,仅当 xx 的个位数字严格小于 kk 除以 1111 的余数时,xx 才是不恰当数。

其中 ⌊x/10⌋\lfloor x / 10 \rfloor 表示 x/10x/10 向下取整。

因此,若 xx 是升序排列下的第 mm 个不恰当数,且 mm 除以 1111 的余数为 cc,则整数 10⋅x+0, 10⋅x+1, …, 10⋅x+(c−1)10 \cdot x + 0,\, 10 \cdot x + 1,\, \ldots,\, 10 \cdot x + (c - 1) 均为不恰当数,而整数 10⋅x+c, 10⋅x+(c+1), …, 10⋅x+910 \cdot x + c,\, 10 \cdot x + (c + 1),\, \ldots,\, 10 \cdot x + 9 均不是不恰当数。

前若干个不恰当数为:1,2,3,4,5,6,7,8,9,10,20,21,30,31,32,…1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 21, 30, 31, 32, \ldots。随后,由于 44 是第 44 个不恰当数,故 40,41,42,4340, 41, 42, 43 是不恰当数,而 44,45,46,…,4944, 45, 46, \ldots, 49 不是不恰当数;由于 1010 是第 1010 个不恰当数,故 100,101,102,…,109100, 101, 102, \ldots, 109 全部是不恰当数;又因 2020 是第 1111 个不恰当数,故 200,201,202,…,209200, 201, 202, \ldots, 209 全都不是不恰当数。

你在旅途中记录下了所见的所有价格。不幸的是,所有整数被拼接成一个巨大的数字字符串 ss,你丢失了相邻整数之间的分隔边界。你现在关心的是:该字符串中,有多少个子串(substring)所表示的数字是不恰当数?若某个子串在不同位置多次出现,则每次出现均单独计数。

输入格式

The only line contains the string ss (1≤∣s∣≤1051 \le |s| \le 10^5), consisting only of digits. It is guaranteed that the first digit of ss is not zero.

仅有一行,包含字符串 ss(1≤∣s∣≤1051 \le |s| \le 10^5),该字符串仅由数字组成。保证 ss 的首位数字不为零。

输出格式

In the only line print the number of substrings of ss that form an inadequate number.

在唯一的一行中输出字符串 ss 中构成不充分数的子串个数。

输入输出样例

  • 输入#1

    4021

    输出#1

    6
  • 输入#2

    110

    输出#2

    3

说明/提示

In the first example the inadequate numbers in the string are 1,2,4,21,40,4021, 2, 4, 21, 40, 402.

In the second example the inadequate numbers in the string are 11 and 1010, and 11 appears twice (on the first and on the second positions).

在第一个例子中,字符串中的不充分数字为 1,2,4,21,40,4021, 2, 4, 21, 40, 402。

在第二个例子中,字符串中的不充分数字为 11 和 1010,且 11 出现了两次(分别位于第一和第二位置)。

输入解题思路,AI测评打分。不知道怎么写?

首页