Codeforces Round #324 (Div. 2) C. Marina and Vasya Set

Source: Internet
Author: User

C. Marina and Vasya

Marina loves strings of the same length and Vasya loves when there was a third string, different from them in exactly C3>t characters. Help Vasya find at least one such string.

More formally, given and stringss1, s2 of length n and number T. Let's denote as F(a, b) The number of characters in which strings a and c13>b is different. Then your task'll be the find any string s3 of the length n, such that f (s1, s3) = F(s2, s3) = T. If There is no such string, print -1.

Input

The first line contains integers n and t (1≤ n ≤105, 0≤ tn).

The second line contains string s1 of length n, consisting of lowercase 中文版 lette Rs.

The third line contain string s2 of length n, consisting of lowercase 中文版 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 中文版 letters. If such string doesn ' t exist, print-1.

Sample Test (s) input
3 2
Abc
Xyc
Output
Ayd
Input
1 0
C
B
Output
-1

Test instructions: give you two strings of the same length as n, so that you can construct a string that is different from any of the two strings that are given with the number of letters T
The puzzle: I am set disorderly, the code ability is poor, beg for understanding
///1085422276#include <bits/stdc++.h>using namespacestd; typedefLong Longll;#defineMem (a) memset (A,0,sizeof (a))#defineMeminf (a) memset (A,127,sizeof (a));#defineTS printf ("111111\n");#definefor (I,A,B) for (int i=a;i<=b;i++)#defineForj (I,A,B) for (int i=a;i>=b;i--)#defineREAD (a,b,c) scanf ("%d%d%d", &a,&b,&c)#defineINF 100000inline ll read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//****************************************#defineMAXN 100000+10Set<int>G;Set<int>:: iterator it;CharA[MAXN],B[MAXN],C[MAXN];intMain () {intn=read (); intt=read (); scanf ("%s%s", A, b); For (I,0, N-1)     if(a[i]==B[i])         G.insert (i); T=n-T; if(t>g.size ()) {        intTmp= (N-g.size ())/2; if(Tmp<t-g.size ()) {cout<<-1<<endl;return 0;}  for(It=g.begin (); It!=g.end (); it++) c[*it]=a[*it]; T=t-g.size (); intflag=1;intFlag2=0;  for(intI=0; i<n;i++)        {            if(G.count (i) = =0&&flag&&t) {C[i]=A[i]; Flag=0; Flag2=1; }            Else if(G.count (i) = =0&&flag2&&t) {C[i]=B[i]; T--; Flag=1; Flag2=0; }            Else if(G.count (i) = =0){                  for(intj=0;j< -; j + +)                    if('a'+j!=a[i]&&'a'+j!=B[i]) {C[i]='a'+j; Break; }            }        }    }    Else {         for(It=g.begin (); It!=g.end (); it++)        {            if(t!=0) {c[*it]=a[*it]; T--; }Else {              for(intj=0;j< -; j + +)                    if('a'+j!=a[*it]&&'a'+j!=b[*it]) {c[*it]='a'+j; Break; }}        }         for(intI=0; i<n;i++)        {            if(G.count (i) = =0)            {                 for(intj=0;j< -; j + +)                    if('a'+j!=a[i]&&'a'+j!=B[i]) {C[i]='a'+j; Break; }            }        }    }  for(intI=0; i<n;i++) printf ("%c", C[i]); return 0;}
Code

Codeforces Round #324 (Div. 2) C. Marina and Vasya Set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.