CF2228C2.Cirno and Number (Hard Version)
普及/提高-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Led On by a Cow to Visit Zenkou Temple
— Neo-traditionalism of Japan
This is the hard version of the problem. The difference between the versions is that in this version, 1≤n≤10. You can hack only if you solved all versions of this problem.
You are given a non-negative integer a and a non-empty, strictly increasing sequence of digits d of length n, where 0≤di≤9.
Find the minimum value of ∣a−b∣ over all non-negative integers b whose decimal representation contains only digits from d.
奶牛引路,参访善光寺
——日本新传统主义
本题为困难版本。两个版本的区别在于:本版本中 1≤n≤10。仅当您已解决本题所有版本时,才可进行 Hack。
给定一个非负整数 a 和一个长度为 n 的、非空且严格递增的数字序列 d(即每位数字满足 0≤di≤9)。
求所有满足以下条件的非负整数 b 中,∣a−b∣ 的最小值:b 的十进制表示中仅包含序列 d 中的数字。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤104). The description of the test cases follows.
The first line of each test case contains two integers a and n (0≤a≤1017, 1≤n≤10).
The second line contains n integers d1,d2,…,dn. It is guaranteed that 0≤d1<d2<…<dn≤9.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤104)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 a 和 n(0≤a≤1017,1≤n≤10)。
第二行包含 n 个整数 d1,d2,…,dn。保证 0≤d1<d2<…<dn≤9。
输出格式
For each test case, output the minimum value of ∣a−b∣.
对于每个测试用例,输出 ∣a−b∣ 的最小值。
输入输出样例
输入#1
4 0 1 0 11 2 1 2 222 3 3 4 5 3333 4 6 7 8 9
输出#1
0 0 111 2334
说明/提示
In the first test case, a=0, b=0, and ∣a−b∣=0.
In the second test case, a=11, b=11, and ∣a−b∣=0.
In the third test case, a=222, b=333, and ∣a−b∣=111.
In the fourth test case, a=3333, b=999, and ∣a−b∣=2334.
在第一个测试用例中,a=0,b=0,且 ∣a−b∣=0。
在第二个测试用例中,a=11,b=11,且 ∣a−b∣=0。
在第三个测试用例中,a=222,b=333,且 ∣a−b∣=111。
在第四个测试用例中,a=3333,b=999,且 ∣a−b∣=2334。
输入解题思路,AI测评打分。不知道怎么写?