CF1560F2.Nearest Beautiful Number (hard version)

提高+/省选-

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

It is a complicated version of problem F1. The difference between them is the constraints (F1: k≤2k \le 2, F2: k≤10k \le 10).

You are given an integer nn. Find the minimum integer xx such that x≥nx \ge n and the number xx is kk-beautiful.

A number is called kk-beautiful if its decimal representation having no leading zeroes contains no more than kk different digits. E.g. if k=2k = 2, the numbers 34344433434443, 5555055550, 777777 and 2121 are kk-beautiful whereas the numbers 120120, 445435445435 and 998244353998244353 are not.

这是问题 F1 的一个复杂版本。它们之间的区别在于约束条件(F1:k≤2k \le 2,F2:k≤10k \le 10)。

给你一个整数 nn。请找出最小的整数 xx,使得 x≥nx \ge n 且 xx 是 kk-beautiful 的。

若一个数的十进制表示(不含前导零)中至多包含 kk 个不同的数字,则称该数为 kk-beautiful。例如,当 k=2k = 2 时,数字 34344433434443、5555055550、777777 和 2121 是 kk-beautiful 的,而数字 120120、445435445435 和 998244353998244353 则不是。

输入格式

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

Each test case consists of one line containing two integers nn and kk (1≤n≤1091 \le n \le 10^9, 1≤k≤101 \le k \le 10).

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。随后是 tt 个测试用例。

每个测试用例由一行组成,包含两个整数 nn 和 kk(1≤n≤1091 \le n \le 10^9,1≤k≤101 \le k \le 10)。

输出格式

For each test case output on a separate line xx — the minimum kk-beautiful integer such that x≥nx \ge n.

对于每个测试用例,在单独一行输出 xx —— 满足 x≥nx \ge n 的最小 kk-beautiful 整数。

输入输出样例

  • 输入#1

    6
    2021 3
    177890 2
    34512 3
    724533 4
    998244353 1
    12345678 10

    输出#1

    2021
    181111
    34533
    724542
    999999999
    12345678

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

首页