CF1759F.All Possible Digits
普及+/提高
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A positive number x of length n in base p (2≤p≤109) is written on the blackboard. The number x is given as a sequence a1,a2,…,an (0≤ai<p) — the digits of x in order from left to right (most significant to least significant).
Dmitry is very fond of all the digits of this number system, so he wants to see each of them at least once.
In one operation, he can:
- take any number x written on the board, increase it by 1, and write the new value x+1 on the board.
For example, p=5 and x=2345.
- Initially, the board contains the digits 2, 3 and 4;
- Dmitry increases the number 2345 by 1 and writes down the number 2405. On the board there are digits 0,2,3,4;
- Dmitry increases the number 2405 by 1 and writes down the number 2415. Now the board contains all the digits from 0 to 4.
Your task is to determine the minimum number of operations required to make all the digits from 0 to p−1 appear on the board at least once.
一个正整数 x(在 p 进制下,其中 2≤p≤109)被写在黑板上,其长度为 n。该数 x 以序列 a1,a2,…,an(其中 0≤ai<p)的形式给出——即 x 在 p 进制下的各位数字,从左到右(从最高位到最低位)排列。
德米特里非常喜爱该进制系统中的所有数字,因此他希望黑板上至少出现每个数字 0 到 p−1 各一次。
每次操作中,他可以执行以下操作之一:
- 任取黑板上的一个数 x,将其加 1,并将新值 x+1 写在黑板上。
例如,当 p=5 且 x=2345 时:
- 最初,黑板上包含数字 2、3 和 4;
- 德米特里将 2345 加 1,写下 2405;此时黑板上的数字为 0、2、3、4;
- 德米特里再将 2405 加 1,写下 2415;此时黑板上已包含 0 至 4 的所有数字。
你的任务是确定所需的最少操作次数,使得黑板上至少出现每个数字 0 到 p−1 各一次。
输入格式
The first line of the input contains a single integer t (1≤t≤2⋅103) — the number of test cases. The descriptions of the input test cases follow.
The first line of description of each test case contains two integers n (1≤n≤100) and p (2≤p≤109) — the length of the number and the base of the number system.
The second line of the description of each test case contains n integers a1,a2,…,an (0≤ai<p) — digits of x in number system with base p
It is guaranteed that the number x does not contain leading zeros (that is, a1>0).
输入的第一行包含一个整数 t(1≤t≤2⋅103),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的描述第一行为两个整数 n(1≤n≤100)和 p(2≤p≤109),分别表示数字的位数及所用进制。
每个测试用例的描述第二行为 n 个整数 a1,a2,…,an(0≤ai<p),表示 x 在 p 进制下的各位数字。
保证数字 x 不含前导零(即 a1>0)。
输出格式
For each test case print a single integer — the minimum number of operations required for Dmitry to get all the digits on the board from 0 to p−1.
It can be shown that this always requires a finite number of operations.
对于每个测试用例,输出一个整数——Dmitry 在黑板上得到从 0 到 p−1 的所有数字所需的最少操作次数。
可以证明,这总是只需要有限次操作。
输入输出样例
输入#1
11 2 3 1 2 4 2 1 1 1 1 6 6 1 2 3 4 5 0 5 2 1 0 1 0 1 3 10 1 2 3 5 1000 4 1 3 2 5 3 5 2 3 4 4 4 3 2 3 0 1 3 2 5 5 1 2 2 2 4 3 4 1 0 1
输出#1
1 1 0 0 7 995 2 1 1 1 2
输入解题思路,AI测评打分。不知道怎么写?