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

44 篇文章 0 订阅
7 篇文章 0 订阅


                             

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


time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 s1s2 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 ≤ 1050 ≤ 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的字符串s1,s2,s3。f(s1, s3) = f(s2, s3) = t,

s1,s3有t个字符不同,s2,s3有t个字符不同。给你 n,t,s1,s2求s3。

如果没有输出-1。


分析:s1,s2相同的sum个  如果 n-t-sum>(n-sum)/2  

不存在这样的s3 ,-1。




#include 
     
     
      
      
#include 
      
      
       
       
#include 
       
       
        
        
using namespace std;
const int N=100005;
char s1[N],s2[N],s3[N];
int b[N];
int main()
{
    int t,n,i,a,sum=0;
    scanf("%d%d",&n,&t);
    scanf("%s%s",s1,s2);
    for(i=0; i
        
        
         
         (n-sum)/2) printf("-1\n");
    else
    {
        if(sum>=n-t)
        {
            int k=n-t;
            for(i=0; i
         
         
           0) { if(b[i]==0) { if((s1[i]-'a'+1)%26==s2[i]-'a') s3[i]=(s1[i]-'a'+2)%26+'a'; else s3[i]=(s1[i]-'a'+1)%26+'a'; } else { s3[i]=s1[i]; k--; } } else { if((s1[i]-'a'+1)%26==s2[i]-'a') s3[i]=(s1[i]-'a'+2)%26+'a'; else s3[i]=(s1[i]-'a'+1)%26+'a'; } } } else { int ss1=n-t-sum,ss2=n-t-sum; for(i=0; i 
          
            0) { s3[i]=s1[i]; ss1--; } else if(ss2>0) { s3[i]=s2[i]; ss2--; } else { if((s1[i]-'a'+1)%26==s2[i]-'a') s3[i]=(s1[i]-'a'+2)%26+'a'; else s3[i]=(s1[i]-'a'+1)%26+'a'; } } } } printf("%s\n",s3); } return 0; } 
           
         
        
        
       
       
      
      
     
     


                             

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值