CF1213E.Two Small Strings

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two strings ss and tt both of length 22 and both consisting only of characters 'a', 'b' and 'c'.

Possible examples of strings ss and tt: "ab", "ca", "bb".

You have to find a string resres consisting of 3n3n characters, nn characters should be 'a', nn characters should be 'b' and nn characters should be 'c' and ss and tt should not occur in resres as substrings.

A substring of a string is a contiguous subsequence of that string. So, the strings "ab", "ac" and "cc" are substrings of the string "abacc", but the strings "bc", "aa" and "cb" are not substrings of the string "abacc".

If there are multiple answers, you can print any of them.

给你两个长度均为 22 的字符串 ss 和 tt,它们仅由字符 'a'、'b' 和 'c' 组成。

字符串 ss 和 tt 的一些可能示例:"ab"、"ca"、"bb"。

你需要构造一个长度为 3n3n 的字符串 resres,其中恰好包含 nn 个 'a'、nn 个 'b' 和 nn 个 'c',且 ss 和 tt 均不能作为 resres 的子串出现。

字符串的子串是指该字符串的一个连续子序列。例如,字符串 "abacc" 的子串包括 "ab"、"ac" 和 "cc",但 "bc"、"aa" 和 "cb" 不是 "abacc" 的子串。

如果存在多个合法答案,输出任意一个即可。

输入格式

The first line of the input contains one integer nn (1≤n≤1051 \le n \le 10^5) — the number of characters 'a', 'b' and 'c' in the resulting string.

The second line of the input contains one string ss of length 22 consisting of characters 'a', 'b' and 'c'.

The third line of the input contains one string tt of length 22 consisting of characters 'a', 'b' and 'c'.

输入的第一行包含一个整数 nn(1≤n≤1051 \le n \le 10^5)——表示最终字符串中字符 'a'、'b' 和 'c' 的总个数。

输入的第二行包含一个长度为 22 的字符串 ss,由字符 'a'、'b' 和 'c' 组成。

输入的第三行包含一个长度为 22 的字符串 tt,由字符 'a'、'b' 和 'c' 组成。

输出格式

If it is impossible to find the suitable string, print "NO" on the first line.

Otherwise print "YES" on the first line and string resres on the second line. resres should consist of 3n3n characters, nn characters should be 'a', nn characters should be 'b' and nn characters should be 'c' and ss and tt should not occur in resres as substrings.

If there are multiple answers, you can print any of them.

如果无法找到满足条件的字符串,则在第一行输出 "NO"。

否则,在第一行输出 "YES",在第二行输出字符串 resres。resres 应当由 3n3n 个字符组成,其中恰好包含 nn 个字符 'a'、nn 个字符 'b' 和 nn 个字符 'c',且 ss 和 tt 均不能作为子串出现在 resres 中。

若存在多个合法答案,输出任意一个即可。

输入输出样例

  • 输入#1

    2
    ab
    bc

    输出#1

    YES
    acbbac
  • 输入#2

    3
    aa
    bc

    输出#2

    YES
    cacbacbab
  • 输入#3

    1
    cb
    ac

    输出#3

    YES
    abc

输入解题思路,AI测评打分。不知道怎么写?

首页