codeforces 584C Marina and Vasya

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 2abcxyc

Output

ayd

Input

1 0cb
 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
时间: 2024-10-12 11:14:09

codeforces 584C Marina and Vasya的相关文章

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

                                                      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. Mor

Educational Codeforces Round 26 E - Vasya&#39;s Function

数论题还是好恶心啊. 题目大意:给你两个不超过1e12的数 x,y,定义一个f ( x, y ) 如果y==0 返回 0 否则返回1+ f ( x , y - gcd( x , y ) ); 思路:我们设gcd ( x , y) 为G,那么 设 x  = A*G,y = B*G,我们考虑减去多少个G时x y 的gcd会改变,我们设减去 k个G的时候 x和y 的gcd为改变,即 A*G 和 ( B - k ) * G 的 gcd 改变了,什么情况下会改变呢,就是A 和( B -  k )的gcd

Codeforces Round #324 (Div. 2)

今天写写cf上以前的水题,找找自信 A. Olesya and Rodion 此题要求一个能被t整除的n位数,直接t为开始,后面全部为0. 当然,需要排除位数为1但t=10的情况. #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; int main() { int n,t,i; scanf("%d%d"

Educational Codeforces Round 48

Educational Codeforces Round 48 C.Vasya And The Mushrooms 思路很简单,走法有一个统一形式就是先上下走,然后到某个位置左右一个来回.然后就推一下,后边那段的递推式子,枚举改变走法的位置即可.看出做法之后发现要推个式子,于是跑去写D了...然后D一开始思路错了...凉啊 #include <bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;++i) #define per(i,a,b

Gym 240668 - A/B/C/D/E - (Done)

链接:https://codeforces.com/gym/240668 A - Olesya and Rodion - [水] 题解:注意到 $t$ 的范围是 $[2,10]$,对于位数小于 $2 \times 3 \times \cdots \times 10 = 3628800$ 的数,暴力枚举去找:否则就直接在 $3628800$ 后面补零即可. AC代码: #include<bits/stdc++.h> using namespace std; int n,t; int p10[8]

codeforces 493C Vasya and Basketball (枚举+模拟+思维)

C. Vasya and Basketball time limit per test 2 seconds memory limit per test 256 megabytes Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 point

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

Codeforces Round #319 (Div. 2) C Vasya and Petya&#39;s Game

因为所有整数都能被唯一分解,p1^a1*p2^a2*...*pi^ai,而一次询问的数可以分解为p1^a1k*p2^a2k*...*pi^aik,这次询问会把所有a1>=a1k && a2 >= a2k &&... a3 >= a3k的数从原来的集合中分开.ai表示pi的幂. 那么只有当这个数的素因子的最大幂都被询问过一次,这个数才能确定.因此答案是所有的不大于n的只有一个素因子的数. #include<bits/stdc++.h> using

CodeForces 577C Vasya and Petya&#39;s Game 数学

题意就是给你一个1到n的范围 你每次可以问这个数是否可以被某一个数整除 问你要猜多少数才能确定这个数…… 一开始一点思路也没有 后来查了一下才知道 每个数都可以分为几个质数的整数次幂相乘得到…… 1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 #include<math.h> 5 #include<string.h> 6 #include<string>