CF1845C.Strong Password

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Monocarp finally got the courage to register on ForceCoders. He came up with a handle but is still thinking about the password.

He wants his password to be as strong as possible, so he came up with the following criteria:

  • the length of the password should be exactly mm;
  • the password should only consist of digits from 00 to 99;
  • the password should not appear in the password database (given as a string ss) as a subsequence (not necessarily contiguous).

Monocarp also came up with two strings of length mm: ll and rr, both consisting only of digits from 00 to 99. He wants the ii-th digit of his password to be between lil_i and rir_i, inclusive.

Does there exist a password that fits all criteria?

Monocarp 终于鼓起勇气在 ForceCoders 上注册了。他想好了用户名,但仍在思考密码。

他希望自己的密码尽可能强,因此制定了以下要求:

  • 密码长度必须恰好为 mm;
  • 密码只能由数字 00 到 99 组成;
  • 密码不能作为子序列(不一定是连续的)出现在密码数据库中(以字符串 ss 给出)。

此外,Monocarp 还构造了两个长度均为 mm 的字符串 ll 和 rr,二者均由数字 00 到 99 组成。他要求自己密码的第 ii 位数字必须在 lil_i 和 rir_i 之间(含端点)。

是否存在一个满足所有条件的密码?

输入格式

The first line contains a single integer tt (1≤t≤1041 \le t \le 10^4) — the number of testcases.

The first line of each testcase contains a string ss (1≤∣s∣≤3⋅1051 \le |s| \le 3 \cdot 10^5), consisting only of digits from 00 to 99 — the password database.

The second line contains a single integer mm (1≤m≤101 \le m \le 10) — the required length of the password.

The third line contains a string ll (∣l∣=m|l| = m), consisting only of digits from 00 to 99 — the lower restriction on each digit.

The fourth line contains a string rr (∣r∣=m|r| = m), consisting only of digits from 00 to 99 — the upper restriction on each digit. li≤ril_i \le r_i for all ii from 11 to mm.

The sum of lengths of ss over all testcases doesn't exceed 3⋅1053 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \le t \le 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个字符串 ss(1≤∣s∣≤3⋅1051 \le |s| \le 3 \cdot 10^5),仅由数字 00 到 99 组成 —— 密码数据库。

每个测试用例的第二行包含一个整数 mm(1≤m≤101 \le m \le 10)—— 所需密码的长度。

每个测试用例的第三行包含一个字符串 ll(∣l∣=m|l| = m),仅由数字 00 到 99 组成 —— 每一位数字的下界限制。

每个测试用例的第四行包含一个字符串 rr(∣r∣=m|r| = m),仅由数字 00 到 99 组成 —— 每一位数字的上界限制。对所有 ii(1≤i≤m1 \le i \le m),满足 li≤ril_i \le r_i。

所有测试用例中字符串 ss 的长度总和不超过 3⋅1053 \cdot 10^5。

输出格式

For each testcase, print "YES" if there exists a password that fits all criteria. Print "NO" otherwise.

对于每个测试用例,如果存在一个满足所有条件的密码,则输出 “YES”;否则输出 “NO”。

输入输出样例

  • 输入#1

    5
    88005553535123456
    2
    50
    56
    123412341234
    3
    111
    444
    1234
    4
    4321
    4321
    459
    2
    49
    59
    00010
    2
    10
    11

    输出#1

    YES
    NO
    YES
    NO
    YES

说明/提示

In the first testcase, Monocarp can choose password "50". It doesn't appear in ss as a subsequence.

In the second testcase, all combinations of three digits, each of them being from 11 to 44, fit the criteria on ll and rr. However, all of them appear in ss as subsequences. For example, "314" appears at positions [3,5,12][3, 5, 12] and "222" appears at positions [2,6,10][2, 6, 10].

In the third testcase, Monocarp can choose password "4321". Actually, that is the only password that fits the criteria on ll and rr. Luckily, it doesn't appear in ss as a subsequence.

In the fourth testcase, only "49" and "59" fit the criteria on ll and rr. Both of them appear in ss as subsequences.

In the fifth testcase, Monocarp can choose password "11".

在第一个测试用例中,Monocarp 可以选择密码 “50”。它不会作为子序列出现在 ss 中。

在第二个测试用例中,所有由三个数字组成的组合(每个数字均取自 11 到 44)均满足关于 ll 和 rr 的限制条件。然而,它们全部都会作为子序列出现在 ss 中。例如,“314” 出现在位置 [3,5,12][3, 5, 12] 上,而 “222” 出现在位置 [2,6,10][2, 6, 10] 上。

在第三个测试用例中,Monocarp 可以选择密码 “4321”。实际上,这是唯一一个满足关于 ll 和 rr 的限制条件的密码。幸运的是,它不会作为子序列出现在 ss 中。

在第四个测试用例中,仅有 “49” 和 “59” 满足关于 ll 和 rr 的限制条件。但它们均会作为子序列出现在 ss 中。

在第五个测试用例中,Monocarp 可以选择密码 “11”。

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

首页