Time Limit: 1000MS |
| Memory Limit: 262144KB |
| 64bit IO Format: %I64d & %I64u |
CodeForces - 584C Marina and Vasya Submit Status Description Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly tcharacters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number t. Let's denote as f(a, b) the number of characters in which strings a and b are different. Then your task will be to find any string s3 of length n, such that f(s1, s3) = f(s2, s3) = t. If there is no such string, print - 1. Input The first line contains two integers n and t (1 ≤ n ≤ 105, 0 ≤ t ≤ n). The second line contains string s1 of length n, consisting of lowercase English letters. The third line contain string s2 of length n, consisting of lowercase English letters. Output Print a string of length n, differing from string s1 and from s2 in exactly t Sample Input Input 3 2abcxyc Output ayd Input 1 0cb Output -1 Source Codeforces Round #324 (Div. 2) //题意: 给出两个长度为n的字符串,先要求构造出一个长度也为n的串使其满足其与这两个串在相同位置不相同的字符数有m个,如果不存在这样的串则输出-1 //思路:先找出两个串相同的字母的个数k,那么不同的个数为mm=n-k; 通过模拟可以知道当2*m<mm时肯定输出-1; 当符合情况时可以分两种: 1、当m+k>=n时:先将两串相同位置的不同的的mm个字符变成不等于它们的字符,然后肯定要有(m-mm)个位置相同的相同字符变成与它们不同的字符,剩下的都是相同的就行了。 2、当mm<2*t时:那么相同位置的相同字符直接输出即可,相同位置的不同字符有(mm-m)个a串的字符,有(mm-m)个b串字符,其余的是与a,b串都不相同的字符。(不太理解的可以自己找例子模拟一下就懂了) Hait:要注意新串的字符都是 ‘a’<=s<='z'的。(在这块WA了5次)。
|