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
output
-1

题意:给你两个长度一样n的字符串,让你再构造一个字符串是的它与任意这给出的俩个字符串不同字母个数为t
题解:我是set乱作的,代码能力差,求谅解
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define TS printf("111111\n");
#define FOR(i,a,b) for( int i=a;i<=b;i++)
#define FORJ(i,a,b) for(int i=a;i>=b;i--)
#define READ(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define inf 100000
inline ll read()
{
ll x=,f=;
char ch=getchar();
while(ch<''||ch>'')
{
if(ch=='-')f=-;
ch=getchar();
}
while(ch>=''&&ch<='')
{
x=x*+ch-'';
ch=getchar();
}
return x*f;
}
//****************************************
#define maxn 100000+10 set<int >G;
set<int >::iterator it;
char a[maxn],b[maxn],c[maxn];
int main()
{ int n=read();
int t=read();
scanf("%s%s",a,b);
FOR(i,,n-)
if(a[i]==b[i])
G.insert(i);
t=n-t;
if(t>G.size())
{
int tmp=(n-G.size())/;
if(tmp<t-G.size()){cout<<-<<endl;return ;}
for(it=G.begin();it!=G.end();it++)c[*it]=a[*it];
t=t-G.size();
int flag=;int flag2=;
for(int i=;i<n;i++)
{
if(G.count(i)==&&flag&&t)
{
c[i]=a[i];
flag=;
flag2=;
}
else if(G.count(i)==&&flag2&&t)
{
c[i]=b[i];
t--;
flag=;
flag2=;
}
else if(G.count(i)==){
for(int j=;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!=)
{ c[*it]=a[*it];
t--;
}else {
for(int j=;j<;j++)
if('a'+j!=a[*it]&&'a'+j!=b[*it])
{
c[*it]='a'+j;break;
}} }
for(int i=;i<n;i++)
{
if(G.count(i)==)
{
for(int j=;j<;j++)
if('a'+j!=a[i]&&'a'+j!=b[i])
{
c[i]='a'+j;break;
}
}
} } for(int i=;i<n;i++)
printf("%c",c[i]);
return ;
}

代码

Codeforces Round #324 (Div. 2)C. Marina and Vasya set的更多相关文章

  1. Codeforces Round #324 (Div. 2) C. Marina and Vasya 贪心

    C. Marina and Vasya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pr ...

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

    A的万般无奈...后来跑了大牛的这份代码发现, 题意是求一个序列与给定的两个序列有t个不同. 只要保证...对应位置就行了.. 所以处理起来非常方便.............. 可是没有感觉是对应位置 ...

  3. Codeforces Round #324 (Div. 2)解题报告

    ---恢复内容开始--- Codeforces Round #324 (Div. 2) Problem A 题目大意:给二个数n.t,求一个n位数能够被t整除,存在多组解时输出任意一组,不存在时输出“ ...

  4. Codeforces Round #324 (Div. 2)

    CF的rating设置改了..人太多了,决定开小号打,果然是明智的选择! 水 A - Olesya and Rodion #include <bits/stdc++.h> using na ...

  5. Codeforces Round #324 (Div. 2) Marina and Vasya 乱搞推理

    原题链接:http://codeforces.com/contest/584/problem/C 题意: 定义$f(s1,s2)$为$s1,s2$不同的字母的个数.现在让你构造一个串$s3$,使得$f ...

  6. Codeforces Round #324 (Div. 2) C (二分)

    题目链接:http://codeforces.com/contest/734/problem/C 题意: 玩一个游戏,一开始升一级需要t秒时间,现在有a, b两种魔法,两种魔法分别有m1, m2种效果 ...

  7. Codeforces Round #324 (Div. 2) E. Anton and Ira 贪心

    E. Anton and Ira Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  8. Codeforces Round #324 (Div. 2) D. Dima and Lisa 哥德巴赫猜想

    D. Dima and Lisa Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/probl ...

  9. Codeforces Round #324 (Div. 2) B. Kolya and Tanya 快速幂

    B. Kolya and Tanya Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/584/pro ...

随机推荐

  1. 怎么在在php配置文件中打开php_fileinfo扩展

    运行composer下载文件时的相关报错截图 处理方法: 在php配置文件中打开php_fileinfo扩展 你需要在查看是否有这个扩展包, 如果有, 那就在php.ini写 extension=ph ...

  2. 用js 转化大小写

    function capitalize(string){ var words =string.split(" "); for(var i=0;i<words.length;i ...

  3. NodeJs中数据库的使用

    另一遍通用的NODEJS数据库方法koa,express,node 通用方法连接MySQL 1.Node.js 连接 MySQL $ cnpm install mysql 连接mysql: var m ...

  4. ubuntu lamnp 环境的安装/卸载 及 配置

    安装mysql--------------------------------------sudo apt install mysql-server   #5.7版本 安装php----------- ...

  5. 创建Tensor

    目录 创建Tensor numpy, list numpy list zeros, ones, fill zeros ones fill random 打乱idx后,a和b的索引不变 constant ...

  6. leetcode-169求众数

    求众数 思路: 记录每个元素出现的次数,然后查找到众数 代码: class Solution: def majorityElement(self, nums: List[int]) -> int ...

  7. 关于使用mongodb中遇到的时间戳雷同的问题

    文不对题,实际上不是时间戳,而是我们使用js取当前毫秒数,将他看为时间戳,每次updata的时候,获取当前毫秒数,把它当做create_time的默认值,自动添加到我们的数据库中,数据模型如下 开始的 ...

  8. Qt 多语言支持

    简介 Qt 多语言支持很强大,很好用. 首先要强调的是程序中需要翻译的字符串最好都用 tr("message") 这种形式,这里的 "message" 就是需要 ...

  9. Quartz.Net 学习之路02 初探Quartz.Net

    第二讲:简单的实例,看看Quartz.Net强在哪里? 直接上代码,代码里有注释: using System; using Quartz; using Quartz.Impl; namespace L ...

  10. ZOJ 3910 Market

    Market Time Limit: 2 Seconds      Memory Limit: 65536 KB There's a fruit market in Byteland. The sal ...