AT_arc224_d.Angst for All Pairs

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

There are NN cards, numbered 11 through NN. Initially, nothing is written on any of the cards.

You can write zero or more positive integers on each card.

The cost of writing a positive integer kk once is equal to the number of digits in the decimal representation of kk.

Determine whether it is possible to satisfy the following condition. If it is possible, output the minimum total cost required; if it is not possible, output −1-1.

  • For every pair of positive integers (x,y)(x,y) satisfying 1≤x<y≤K1 \leq x < y \leq K, there exists a card containing exactly one of xx and yy.

TT test cases are given; solve each of them.

有 NN 张卡片,编号为 11 至 NN。初始时,所有卡片上均未写入任何数字。

你可以在每张卡片上写零个或多个正整数。

每次写入一个正整数 kk 的代价等于 kk 的十进制表示的位数。

请判断是否可能满足以下条件。若可能,输出所需的最小总代价;否则输出 −1-1:

  • 对于每一对满足 1≤x<y≤K1 \leq x < y \leq K 的正整数 (x,y)(x, y),都存在一张卡片,其上恰好包含 xx 和 yy 中的一个(即 xx 和 yy 中恰有一个出现在该卡片上)。

共给出 TT 组测试用例,请对每组分别求解。

输入格式

The input is given from Standard Input in the following format, where casei\mathrm{case}_i denotes the ii-th test case:

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

Each test case is given in the following format:

NN KK

输入从标准输入给出,格式如下,其中 casei\mathrm{case}_i 表示第 ii 个测试用例:

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

每个测试用例的格式如下:

NN KK

输出格式

Output TT lines. The ii-th line should contain the answer for the ii-th test case.

输出 TT 行。第 ii 行应包含第 ii 个测试用例的答案。

输入输出样例

  • 输入#1

    4
    3 5
    100 25
    5 1225
    180 998244

    输出#1

    5
    39
    -1
    17655598

说明/提示

Sample 1 Explanation:
This input contains four test cases.

For the first test case, writing as follows satisfies the condition with a total cost of 55.

  • Write 1,51, 5 on card 11.
  • Write 2,52, 5 on card 22.
  • Write 33 on card 33.

For the second test case, the minimum total cost required to satisfy the condition is 3939.

For the third test case, it is impossible to satisfy the condition, so output −1-1.

For the fourth test case, the minimum total cost required to satisfy the condition is 1765559817655598.

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 1≤N≤1061 \leq N \leq 10^6
  • 2≤K≤1062 \leq K \leq 10^6
  • The sum of NN in each input is at most 10610^6.
  • The sum of KK in each input is at most 10610^6.
  • All input values are integers.

样例 1 解释:
该输入包含四个测试用例。

对于第一个测试用例,按如下方式书写可满足条件,总代价为 55:

  • 在卡片 11 上写 1,51, 5;
  • 在卡片 22 上写 2,52, 5;
  • 在卡片 33 上写 33。

对于第二个测试用例,满足条件所需的最小总代价为 3939。

对于第三个测试用例,无法满足条件,因此输出 −1-1。

对于第四个测试用例,满足条件所需的最小总代价为 1765559817655598。

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 1≤N≤1061 \leq N \leq 10^6
  • 2≤K≤1062 \leq K \leq 10^6
  • 所有输入中 NN 的总和不超过 10610^6。
  • 所有输入中 KK 的总和不超过 10610^6。
  • 所有输入值均为整数。

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

首页