AT_ndpc2026_d.Banknote

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

In the AtCoder Kingdom, banknotes of denominations 11 yen, 1010 yen, 100100 yen, …\dots, 1010010^{100} yen are used.

Alice wants to pay NN yen to Bob. Find the minimum possible total number of banknotes exchanged, which is the sum of:

  • the number of banknotes Alice gives to Bob, and
  • the number of banknotes Bob gives back as change.

More precisely, for any integer M≥NM \geq N, consider:

  • the minimum number of banknotes needed to represent exactly MM yen, and
  • the minimum number of banknotes needed to represent exactly M−NM - N yen.

Find the minimum possible value of their sum.

You are given TT test cases. Solve each of them.

在 AtCoder 王国,流通的纸币面额为 11 日元、1010 日元、100100 日元、…\dots、1010010^{100} 日元。

爱丽丝想向鲍勃支付 NN 日元。求交换纸币的最小总张数,即:

  • 爱丽丝付给鲍勃的纸币张数,加上
  • 鲍勃找零给爱丽丝的纸币张数。

更准确地说,对任意整数 M≥NM \geq N,考虑:

  • 表示恰好 MM 日元所需的最少纸币张数,以及
  • 表示恰好 M−NM - N 日元所需的最少纸币张数。

求上述两者之和的最小可能值。

你将得到 TT 组测试数据,请分别求解每组数据。

输入格式

The input is given from standard input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case is given in the following format:

NN

输入从标准输入中按以下格式给出:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例按以下格式给出:

NN

输出格式

Print TT lines. For the ii-th line, output the answer for the ii-th test case.

输出 TT 行。对于第 ii 行,输出第 ii 个测试用例的答案。

输入输出样例

  • 输入#1

    3
    7
    34
    123456789123456789

    输出#1

    4
    7
    44

说明/提示

Sample 1 Explanation:
In the first test case:

  • Alice pays 1010 yen using one 1010-yen banknote, and
  • Bob returns 33 yen as change using three 11-yen banknotes.

In this case, the total number of banknotes exchanged is 44, which is optimal.

Constraints

  • 1≤T≤1041 \leq T \leq 10^4
  • 1≤N≤10181 \leq N \leq 10^{18}
  • All input values are integers

样例 1 解释:
在第一个测试用例中:

  • 爱丽丝使用一张 10 日元纸币支付 10 日元,且
  • 鲍勃使用三张 1 日元纸币找零 3 日元。

此时,交换的纸币总数为 4 张,这是最优解。

约束条件

  • 1≤T≤1041 \leq T \leq 10^4
  • 1≤N≤10181 \leq N \leq 10^{18}
  • 所有输入值均为整数

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

首页