CF1932E.Final Countdown

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

You are in a nuclear laboratory that is about to explode and destroy the Earth. You must save the Earth before the final countdown reaches zero.

The countdown consists of nn (1≤n≤4⋅1051 \le n \le 4 \cdot 10^5) mechanical indicators, each showing one decimal digit. You noticed that when the countdown changes its state from xx to x−1x-1, it doesn't happen in one move. Instead, each change of a single digit takes one second.

So, for example, if the countdown shows 42, then it will change to 41 in one second, because only one digit is changed, but if the countdown shows 2300, then it will change to 2299 in three seconds, because the three last digits are changed.

Find out how much time is left before the countdown reaches zero.

你身处一座即将爆炸并摧毁地球的核实验室中。在倒计时归零之前,你必须拯救地球。

该倒计时由 nn(1≤n≤4⋅1051 \le n \le 4 \cdot 10^5)个机械指示器组成,每个指示器显示一个十进制数字。你注意到:当倒计时从数值 xx 变为 x−1x-1 时,并非一步完成;相反,每一位数字的变更均需耗时一秒。

例如,若倒计时当前显示为 42,则它将在一秒后变为 41(仅有一位数字发生变化);而若倒计时当前显示为 2300,则它将在三秒后变为 2299(最后三位数字均发生变化)。

请计算倒计时归零前剩余的总时间。

输入格式

The first line of input contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of test cases. Then the descriptions of the test cases follow.

The first line of each test case contains a single integer nn (1≤n≤4⋅1051\le n\le 4\cdot 10^5).

The second line contains a string of nn digits, the current state of the countdown. It is guaranteed that at least one digit is not zero.

The sum of nn for all tests does not exceed 4⋅1054\cdot 10^5.

输入的第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含一个整数 nn(1≤n≤4⋅1051\le n\le 4\cdot 10^5)。

第二行包含一个长度为 nn 的数字字符串,表示当前倒计时的状态。保证其中至少有一个数字不为零。

所有测试用例的 nn 值之和不超过 4⋅1054\cdot 10^5。

输出格式

For each test case, print a single integer without leading zeroes, the number of seconds left before the countdown reaches zero. Note that this number may be huge.

对于每个测试用例,输出一个不含前导零的整数,表示倒计时到达零之前剩余的秒数。注意,该数字可能非常大。

输入输出样例

  • 输入#1

    5
    2
    42
    5
    12345
    2
    99
    4
    0005
    27
    456480697259671309012631002

    输出#1

    46
    13715
    108
    5
    507200774732968121125145546

说明/提示

In the first example, there are four changes that take 2 seconds: 40 to 39, 30 to 29, 20 to 19, and 10 to 09, other changes take 1 second each. So the total time is 2⋅4+1⋅(42−4)=462\cdot 4 + 1\cdot(42-4) = 46.

在第一个例子中,有四次变化耗时 2 秒:40 → 39、30 → 29、20 → 19 和 10 → 09,其余变化各耗时 1 秒。因此总耗时为 2⋅4+1⋅(42−4)=462\cdot 4 + 1\cdot(42-4) = 46。

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

首页