码迷,mamicode.com
首页 > 其他好文 > 详细

codeforces 584C Marina and Vasya

时间:2015-11-27 00:41:56      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

C. Marina and Vasya

 
 

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 t characters. Your string should consist only from lowercase English letters. If such string doesn‘t exist, print -1.

Sample test(s)
Input
3 2
abc
xyc
Output
ayd
Input
1 0
c
b
 1 #include<cstdio>
 2 #include<vector>
 3 #include<cmath>
 4 #include<queue>
 5 #include<map>
 6 #include<cstring>
 7 #include<algorithm>
 8 using namespace std;
 9 typedef long long ll;
10 typedef unsigned long long ull;
11 const int maxn=100005;
12 int main()
13 {
14     int t,n;
15     char s1[maxn],s2[maxn],s3[maxn];
16     scanf("%d%d",&n,&t);
17     scanf("%s%s",s1,s2);
18     t=n-t;
19     int k1=0,k2=0;
20     for(int i=0;i<n;i++)
21     {
22         if(s1[i]==s2[i]&&(k1<t&&k2<t))s3[i]=s1[i],k1++,k2++;
23         else if(s1[i]!=s2[i]||k1==t)
24             for(int j=0;j<26;j++)
25             if(s1[i]!=a+j&&s2[i]!=a+j)
26             {
27                 s3[i]=(char)(a+j);
28                 break;
29             }
30     }
31     if(k1==t)
32     {
33         puts(s3);
34         return 0;
35     }
36     for(int i=0;i<n;i++)
37     {
38         if(s1[i]==s2[i])continue;
39         if(k1<t)
40             s3[i]=s1[i],k1++;
41         else if(k2<t)
42             s3[i]=s2[i],k2++;
43         else
44         for(int j=0;j<26;j++)
45         if(s1[i]!=a+j&&s2[i]!=a+j)
46         {
47             s3[i]=(char)(a+j);
48             break;
49         }
50     }
51     if(k1<t||k2<t)puts("-1");
52     else puts(s3);
53     return 0;
54 }

 

Output
-1

codeforces 584C Marina and Vasya

标签:

原文地址:http://www.cnblogs.com/homura/p/4999324.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!