C - Marina and Vasya CodeForces - 584C (思维)

版权声明: https://blog.csdn.net/nucleare/article/details/89337077

C - Marina and Vasya

 CodeForces - 584C 

Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. 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 tcharacters. Your string should consist only from lowercase English letters. If such string doesn't exist, print -1.

Examples

Input

扫描二维码关注公众号,回复: 6125945 查看本文章
3 2
abc
xyc

Output

ayd

Input

1 0
c
b

Output

-1

题意:给了两个长度为n的字符串让你构造一个字符串使得这个字符串跟给出的两个字符串每个有t个字符不同,

 f(s1, s3) = f(s2, s3) = t. s3为构造的字符串;

思路:乱搞,贪心的选出n-t个相同的,默认两个字符串原来的相同的为以构造的。。。

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;

char s1[N], s2[N], m;
char getc(char ch) {
	m++;
	if (m > 104) m = 7;
	return ((ch - 'a' + m) % 26 + 'a');
}
int main() {
	
	int n, t;
	scanf ("%d %d", &n, &t);
	scanf ("%s %s", s1+1, s2+1);
	int k = 0;
	for (int i = 1; i <= n; ++i) {
		if (s1[i] == s2[i]) ++k;
	}
	if ((n - k)/2 + k < n - t) {
		puts("-1");
		return 0;
	}
	char ch;
	int kk = 0;
	int k1 = 0, k2 = 0;
	for (int i = 1; i <= n; ++i) {
		if (s1[i] == s2[i]) {
			if (kk < k && kk < n - t) {
				printf ("%c", s1[i]);
				++kk;
			} else {
				ch = getc(s1[i]);
				if (ch == s1[i]) ch = getc(s1[i]);
				printf ("%c", ch);
			}
		} else {
			if (k + k1 < n - t) {
				printf("%c", s1[i]);
				++k1;
			} else if (k + k2 < n - t) {
				printf("%c", s2[i]);
				++k2;
			} else {
				ch = getc(s1[i]);
				while (ch == s2[i] || ch == s1[i]) {
					ch = getc(s1[i]);
				}
				printf ("%c", ch);
			}
		}
		//printf ("%d %d %d\n", k, k1, k2);
	}
	puts("");
//	5 2
//abaac
//bbbaa
//abcaf
	return 0;
}

猜你喜欢

转载自blog.csdn.net/nucleare/article/details/89337077