CF1835A.k-th equality

普及+/提高

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Consider all equalities of form a+b=ca + b = c, where aa has AA digits, bb has BB digits, and cc has CC digits. All the numbers are positive integers and are written without leading zeroes. Find the kk-th lexicographically smallest equality when written as a string like above or determine that it does not exist.

For example, the first three equalities satisfying A=1A = 1, B=1B = 1, C=2C = 2 are

  • 1+9=101 + 9 = 10,
  • 2+8=102 + 8 = 10,
  • 2+9=112 + 9 = 11.

An equality ss is lexicographically smaller than an equality tt with the same lengths of the numbers if and only if the following holds:

  • in the first position where ss and tt differ, the equality ss has a smaller digit than the corresponding digit in tt.

考虑所有形如 a+b=ca + b = c 的等式,其中 aa 有 AA 位数字,bb 有 BB 位数字,cc 有 CC 位数字。所有数字均为正整数,且均不带前导零。请找出按字典序排列的第 kk 小的等式(将等式视为形如上述的字符串),若不存在则说明之。

例如,满足 A=1A = 1、B=1B = 1、C=2C = 2 的前三个等式为:

  • 1+9=101 + 9 = 10,
  • 2+8=102 + 8 = 10,
  • 2+9=112 + 9 = 11。

当两个等式所含各数的位数相同时,等式 ss 字典序小于等式 tt 当且仅当满足以下条件:

  • 在 ss 与 tt 首次出现差异的位置上,ss 中对应位置的数字小于 tt 中对应位置的数字。

输入格式

Each test contains multiple test cases. The first line of input contains a single integer tt (1≤t≤1031 \leq t \leq 10^3) — the number of test cases. The description of test cases follows.

The first line of each test case contains integers AA, BB, CC, kk (1≤A,B,C≤61 \leq A, B, C \leq 6, 1≤k≤10121 \leq k \leq 10^{12}).

Each input file has at most 55 test cases which do not satisfy A,B,C≤3A, B, C \leq 3.

每个测试包含多个测试用例。输入的第一行包含一个整数 tt(1≤t≤1031 \leq t \leq 10^3),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含整数 AA、BB、CC、kk(1≤A,B,C≤61 \leq A, B, C \leq 6,1≤k≤10121 \leq k \leq 10^{12})。

每个输入文件中,最多有 55 个测试用例不满足 A,B,C≤3A, B, C \leq 3。

输出格式

For each test case, if there are strictly less than kk valid equalities, output −1-1.

Otherwise, output the kk-th equality as a string of form a+b=ca + b = c.

对于每个测试用例,如果有效等式的数量严格少于 kk,则输出 −1-1。

否则,输出第 kk 个等式,格式为字符串 a+b=ca + b = c。

输入输出样例

  • 输入#1

    7
    1 1 1 9
    2 2 3 1
    2 2 1 1
    1 5 6 42
    1 6 6 10000000
    5 5 6 3031568815
    6 6 6 1000000000000

    输出#1

    2 + 1 = 3
    10 + 90 = 100
    -1
    9 + 99996 = 100005
    -1
    78506 + 28543 = 107049
    -1

说明/提示

In the first test case, the first 99 solutions are: ⟨1,1,2⟩,⟨1,2,3⟩,⟨1,3,4⟩,⟨1,4,5⟩,⟨1,5,6⟩,⟨1,6,7⟩,⟨1,7,8⟩,⟨1,8,9⟩,⟨2,1,3⟩\langle 1, 1, 2 \rangle, \langle 1, 2, 3 \rangle, \langle 1, 3, 4 \rangle, \langle 1, 4, 5 \rangle, \langle 1, 5, 6 \rangle, \langle 1, 6, 7 \rangle, \langle 1, 7, 8 \rangle, \langle 1, 8, 9 \rangle, \langle 2, 1, 3 \rangle.

Int the third test case, there are no solutions as the smallest possible values for aa and bb are larger than the maximal possible value of cc — 10+10=20>910 + 10 = 20 \gt 9.

Please note that whitespaces in the output matter.

在第一个测试用例中,前 99 个解为:⟨1,1,2⟩,⟨1,2,3⟩,⟨1,3,4⟩,⟨1,4,5⟩,⟨1,5,6⟩,⟨1,6,7⟩,⟨1,7,8⟩,⟨1,8,9⟩,⟨2,1,3⟩\langle 1, 1, 2 \rangle, \langle 1, 2, 3 \rangle, \langle 1, 3, 4 \rangle, \langle 1, 4, 5 \rangle, \langle 1, 5, 6 \rangle, \langle 1, 6, 7 \rangle, \langle 1, 7, 8 \rangle, \langle 1, 8, 9 \rangle, \langle 2, 1, 3 \rangle。

在第三个测试用例中,不存在解,因为 aa 和 bb 的最小可能取值之和已超过 cc 的最大可能取值——10+10=20>910 + 10 = 20 \gt 9。

请注意,输出中的空白字符(空格)是重要的。

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

首页