CF193C.Hamming Distance
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Hamming distance between strings a and b of equal length (denoted by h(a, b)) is equal to the number of distinct integers i (1 ≤ i ≤ |a|), such that a__i ≠ b__i, where a__i is the i-th symbol of string a, b__i is the i-th symbol of string b. For example, the Hamming distance between strings "aba" and "bba" equals 1, they have different first symbols. For strings "bbba" and "aaab" the Hamming distance equals 4.
John Doe had a paper on which four strings of equal length _s_1, _s_2, _s_3 and _s_4 were written. Each string s__i consisted only of lowercase letters "a" and "b". John found the Hamming distances between all pairs of strings he had. Then he lost the paper with the strings but he didn't lose the Hamming distances between all pairs.
Help John restore the strings; find some four strings s'1, s'2, s'3, s'4 of equal length that consist only of lowercase letters "a" and "b", such that the pairwise Hamming distances between them are the same as between John's strings. More formally, set s'i must satisfy the condition
.
To make the strings easier to put down on a piece of paper, you should choose among all suitable sets of strings the one that has strings of minimum length.
字符串 a 与 b(长度相等)之间的汉明距离(记作 h(a,b))定义为满足 ai=bi 的不同整数 i(其中 1≤i≤∣a∣)的个数;这里 ai 表示字符串 a 的第 i 个字符,bi 表示字符串 b 的第 i 个字符。例如,字符串 "aba" 与 "bba" 之间的汉明距离为 1,因为它们仅在第一个字符处不同;而字符串 "bbba" 与 "aaab" 之间的汉明距离为 4。
约翰·多伊尔(John Doe)曾在一张纸上写下四个等长的字符串 s1,s2,s3 和 s4。每个字符串 si 仅由小写字母 "a" 和 "b" 组成。约翰计算了这四个字符串两两之间的汉明距离,随后却丢失了写有原始字符串的纸张,但保留了所有两两之间的汉明距离值。
请帮助约翰还原这些字符串:找出四个等长字符串 s1′,s2′,s3′,s4′,每个字符串仅由小写字母 "a" 和 "b" 组成,使得它们两两之间的汉明距离与约翰原先的字符串完全相同。更准确地说,集合 {si′} 必须满足条件
。
为便于将字符串书写在纸上,请在所有满足条件的字符串集合中,选择字符串长度最小的一组。
输入格式
The first line contains space-separated integers h(_s_1, _s_2), h(_s_1, _s_3), h(_s_1, _s_4). The second line contains space-separated integers h(_s_2, _s_3) and h(_s_2, _s_4). The third line contains the single integer h(_s_3, _s_4).
All given integers h(s__i, s__j) are non-negative and do not exceed 105. It is guaranteed that at least one number h(s__i, s__j) is positive.
第一行包含三个用空格分隔的整数:h(s1, s2)、h(s1, s3) 和 h(s1, s4)。
第二行包含两个用空格分隔的整数:h(s2, s3) 和 h(s2, s4)。
第三行包含一个整数:h(s3, s4)。
所有给定的整数 h(si, sj) 均为非负数,且不超过 105。保证至少有一个数 h(si, sj) 为正数。
输出格式
Print -1 if there's no suitable set of strings.
Otherwise print on the first line number len — the length of each string. On the i-th of the next four lines print string s'i. If there are multiple sets with the minimum length of the strings, print any of them.
如果不存在合适的字符串集合,则输出 -1。
否则,在第一行输出数字 _len_ —— 即每个字符串的长度;在接下来的四行中,第 i 行输出字符串 s'_i。若存在多个具有最小字符串长度的集合,输出其中任意一个即可。
输入输出样例
输入#1
4 4 4 4 4 4
输出#1
6 aaaabb aabbaa bbaaaa bbbbbb
输入解题思路,AI测评打分。不知道怎么写?