CF868A.Bark to Unlock

入门

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.

Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.

随着技术的发展,制造商正致力于使手机解锁过程尽可能地用户友好。为了解锁其新款手机,阿尔卡季的宠物狗“穆穆”只需吠叫一次密码即可。手机将密码表示为一个由两个小写英文字母组成的字符串。

穆穆的敌人“卡什坦卡”想要解锁穆穆的手机以窃取一些敏感信息,但它只能吠叫 n 个互不相同的单词,每个单词均可表示为一个由两个小写英文字母组成的字符串。卡什坦卡希望依次连续吠叫若干个单词(单词可以重复),从而发出一个包含密码作为子串的字符串。请判断是否可以通过这种方式解锁手机。

输入格式

The first line contains two lowercase English letters — the password on the phone.

The second line contains single integer n (1 ≤ n ≤ 100) — the number of words Kashtanka knows.

The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.

第一行包含两个小写英文字母——手机上的密码。

第二行包含一个整数 nn(1 ≤ n ≤ 1001 ≤ n ≤ 100)——Kashtanka 所知道的单词数量。

接下来的 nn 行每行包含两个小写英文字母,表示 Kashtanka 所知道的单词。这些单词保证互不相同。

输出格式

Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.

You can print each letter in arbitrary case (upper or lower).

如果卡什坦卡能在一行中吠叫若干个单词,从而组成一个包含密码的字符串,则输出 "YES",否则输出 "NO"。

每个字母可以以任意大小写(大写或小写)输出。

输入输出样例

  • 输入#1

    ya
    4
    ah
    oy
    to
    ha

    输出#1

    YES
  • 输入#2

    hp
    2
    ht
    tp

    输出#2

    NO
  • 输入#3

    ah
    1
    ha

    输出#3

    YES

说明/提示

In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".

In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.

In the third example the string "hahahaha" contains "ah" as a substring.

在第一个例子中,密码是 “ya”,而卡什坦卡可以先吠叫 “oy”,再吠叫 “ah”,然后吠叫 “ha”,从而构成字符串 “oyahha”,其中包含该密码。因此,答案是 “YES”。

在第二个例子中,卡什坦卡无法生成一个包含密码作为子串的字符串。注意,它虽然可以先吠叫 “ht”,再吠叫 “tp”,从而生成 “http”,但该字符串并不包含密码 “hp” 作为子串。

在第三个例子中,字符串 “hahahaha” 包含 “ah” 作为子串。

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

首页