CF865E.Hex Dyslexia
NOI/NOI+/CTSC
通过率:0%
时间限制:3.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Copying large hexadecimal (base 16) strings by hand can be error prone, but that doesn't stop people from doing it. You've discovered a bug in the code that was likely caused by someone making a mistake when copying such a string. You suspect that whoever copied the string did not change any of the digits in the string, nor the length of the string, but may have permuted the digits arbitrarily. For example, if the original string was 0_abc_ they may have changed it to a_0_cb or 0_bca_, but not abc or 0_abb_.
Unfortunately you don't have access to the original string nor the copied string, but you do know the length of the strings and their numerical absolute difference. You will be given this difference as a hexadecimal string S, which has been zero-extended to be equal in length to the original and copied strings. Determine the smallest possible numerical value of the original string.
手动复制长十六进制(基数为 16)字符串容易出错,但这并未阻止人们这么做。你发现了一处代码缺陷,其原因很可能是某人在复制此类字符串时出了差错。你推测,该复制者未更改字符串中的任何数字,也未改变字符串的长度,但可能任意重排了这些数字的位置。例如,若原始字符串为 0_abc_,则复制后的字符串可能是 _a_0_cb_ 或 0_bca_,但不可能是 _abc_ 或 0_abb_。
不幸的是,你既无法访问原始字符串,也无法访问复制后的字符串;但你知道这两个字符串的长度,以及它们数值上的绝对差值。该差值将以十六进制字符串 S 的形式给出,且 S 已用前导零填充至与原始字符串和复制字符串等长。请确定原始字符串可能的最小数值。
输入格式
Input will contain a hexadecimal string S consisting only of digits 0 to 9 and lowercase English letters from a to f, with length at most 14. At least one of the characters is non-zero.
输入将包含一个十六进制字符串 S,该字符串仅由数字 0 到 9 和小写英文字母 a 到 f 组成,长度最多为 14。其中至少有一个字符不为零。
输出格式
If it is not possible, print "NO" (without quotes).
Otherwise, print the lowercase hexadecimal string corresponding to the smallest possible numerical value, including any necessary leading zeros for the length to be correct.
如果不可能,输出 “NO”(不带引号)。
否则,输出对应最小可能数值的、小写的十六进制字符串;该字符串长度必须正确,必要时需补前导零。
输入输出样例
输入#1
f1e
输出#1
NO
输入#2
0f1e
输出#2
00f1
输入#3
12d2c
输出#3
00314
说明/提示
The numerical value of a hexadecimal string is computed by multiplying each digit by successive powers of 16, starting with the rightmost digit, which is multiplied by 160. Hexadecimal digits representing values greater than 9 are represented by letters: a = 10, b = 11, c = 12, d = 13, e = 14, f = 15.
For example, the numerical value of 0_f_1_e_ is 0·163 + 15·162 + 1·161 + 14·160 = 3870, the numerical value of 00_f_1 is 0·163 + 0·162 + 15·161 + 1·160 = 241, and the numerical value of 100_f_ is 1·163 + 0·162 + 0·161 + 15·160 = 4111. Since 3870 + 241 = 4111 and 00_f_1 is a permutation of 100_f_, 00_f_1 is a valid answer to the second test case.
十六进制字符串的数值通过将每一位数字乘以 16 的相应幂次得到,从最右侧的数字开始(该位乘以 160)。表示大于 9 的数值的十六进制数字用字母表示:a=10,b=11,c=12,d=13,e=14,f=15。
例如,0_f_1_e_ 的数值为 0⋅163+15⋅162+1⋅161+14⋅160=3870,00_f_1 的数值为 0⋅163+0⋅162+15⋅161+1⋅160=241,而 100_f_ 的数值为 1⋅163+0⋅162+0⋅161+15⋅160=4111。由于 3870+241=4111,且 00_f_1 是 100_f_ 的一个排列,因此 00_f_1 是第二个测试用例的一个有效答案。
输入解题思路,AI测评打分。不知道怎么写?