A16062 | k-th equality
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Consider all equalities of form $a + b = c$ , where $a$ has $A$ digits, $b$ has $B$ digits, and $c$ has $C$ digits. All the numbers are positive integers and are written without leading zeroes. Find the $k$ -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 = 1$ , $B = 1$ , $C = 2$ are
- $1 + 9 = 10$ ,
- $2 + 8 = 10$ ,
- $2 + 9 = 11$ .
An equality $s$ is lexicographically smaller than an equality $t$ with the same lengths of the numbers if and only if the following holds:
- in the first position where $s$ and $t$ differ, the equality $s$ has a smaller digit than the corresponding digit in $t$ .
For example, the first three equalities satisfying $A = 1$ , $B = 1$ , $C = 2$ are
- $1 + 9 = 10$ ,
- $2 + 8 = 10$ ,
- $2 + 9 = 11$ .
An equality $s$ is lexicographically smaller than an equality $t$ with the same lengths of the numbers if and only if the following holds:
- in the first position where $s$ and $t$ differ, the equality $s$ has a smaller digit than the corresponding digit in $t$ .
输入格式
Each test contains multiple test cases. The first line of input contains a single integer $t$ ( $1 \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 $A$ , $B$ , $C$ , $k$ ( $1 \leq A, B, C \leq 6$ , $1 \leq k \leq 10^{12}$ ).
Each input file has at most $5$ test cases which do not satisfy $A, B, C \leq 3$ .
The first line of each test case contains integers $A$ , $B$ , $C$ , $k$ ( $1 \leq A, B, C \leq 6$ , $1 \leq k \leq 10^{12}$ ).
Each input file has at most $5$ test cases which do not satisfy $A, B, C \leq 3$ .
输出格式
For each test case, if there are strictly less than $k$ valid equalities, output $-1$ .
Otherwise, output the $k$ -th equality as a string of form $a + b = c$ .
Otherwise, output the $k$ -th equality as a string of form $a + 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 $9$ solutions are: $\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 $a$ and $b$ are larger than the maximal possible value of $c$ — $10 + 10 = 20 > 9$ .
Please note that whitespaces in the output matter.
Int the third test case, there are no solutions as the smallest possible values for $a$ and $b$ are larger than the maximal possible value of $c$ — $10 + 10 = 20 > 9$ .
Please note that whitespaces in the output matter.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted