CF1823D.Unique Palindromes

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

A palindrome is a string that reads the same backwards as forwards. For example, the string abcba is palindrome, while the string abca is not.

Let p(t)p(t) be the number of unique palindromic substrings of string tt , i. e. the number of substrings t[lr]t[l \dots r] that are palindromes themselves. Even if some substring occurs in tt several times, it's counted exactly once. (The whole string tt is also counted as a substring of tt ).

For example, string tt == abcbbcabcb has p(t)=6p(t) = 6 unique palindromic substrings: a, b, c, bb, bcb and cbbc.

Now, let's define p(s,m)=p(t)p(s, m) = p(t) where t=s[1m]t = s[1 \dots m] . In other words, p(s,m)p(s, m) is the number of palindromic substrings in the prefix of ss of length mm . For example, p(p( abcbbcabcb ,5), 5) == p(p( abcbb )=5) = 5 .

You are given an integer nn and kk "conditions" ( k20k \le 20 ). Let's say that string ss , consisting of nn lowercase Latin letters, is good if all kk conditions are satisfied at the same time. A condition is a pair (xi,ci)(x_i, c_i) and have the following meaning:

  • p(s,xi)=cip(s, x_i) = c_i , i. e. a prefix of ss of length xix_i contains exactly cic_i unique palindromic substrings.

Find a good string ss or report that such ss doesn't exist.Look in Notes if you need further clarifications.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1041 \le t \le 10^4 ). The description of the test cases follows.

The first line of each test case contains two integers nn and kk ( 3n21053 \le n \le 2 \cdot 10^5 ; 1k201 \le k \le 20 ) — length of good string ss and number of conditions.

The second line of each test case contains kk integers x1,x2,,xkx_1, x_2, \dots, x_k ( 3x1<x2<<xk=n3 \le x_1 < x_2 < \dots < x_k = n ) where xix_i is the length of the prefix in the ii -th condition.

The third line of each test case contains kk integers c1,c2,,ckc_1, c_2, \dots, c_k ( 3c1c2ckmin(109,(n+1)n2)3 \le c_1 \le c_2 \le \dots \le c_k \le \min{\left(10^9, \frac{(n + 1) n}{2} \right)} ) where cic_i is the number of palindromic substrings in the ii -th condition.

It is guaranteed that the sum of nn over all test cases does not exceed 21052 \cdot 10 ^ 5 .

输出格式

For each test case, if there is no good string ss of length nn that satisfies all conditions, print NO.

Otherwise, print YES and a string ss of length nn , consisting of lowercase Latin letters, that satisfies all conditions. If there are multiple answers, print any of them.

输入输出样例

  • 输入#1

    7
    10 2
    5 10
    5 6
    3 1
    3
    3
    4 2
    3 4
    3 3
    4 2
    3 4
    3 4
    4 1
    4
    5
    10 3
    4 6 10
    4 5 8
    10 4
    4 6 7 10
    4 5 7 8

    输出#1

    YES
    abcbbcabcb
    YES
    foo
    YES
    ayda
    YES
    wada
    NO
    YES
    abcbcacbab
    NO

说明/提示

In the first test case, string ss == abcbbcabcb satisfies k=2k = 2 conditions:

  • p(s,x1)=p(s,5)=p(s, x_1) = p(s, 5) = p(p( abcbb )=5=s1) = 5 = s_1 . Palindromic substrings are a, b, c, bb and bcb.
  • p(s,x2)=p(s,10)=p(s, x_2) = p(s, 10) = p(p( abcbbcabcb )=6=s2) = 6 = s_2 . Palindromic substrings are the same as above, and one extra substring cbbc.

In the second test case, string foo satisfies k=1k = 1 condition:

  • p(p( foo )=3) = 3 . Palindromic substrings are f, o and oo.

There are other possible answers.In the third test case, string ayda satisfies k=2k = 2 conditions:

  • p(p( ayd )=3) = 3 . Palindromic substrings are a, y and d.
  • p(p( ayda )=3) = 3 . Palindromic substrings are the same.

In the fourth test case, string wada satisfies k=2k = 2 conditions:

  • p(p( wad )=3) = 3 . Palindromic substrings are w, a and d.
  • p(p( wada )=4) = 4 . Palindromic substrings are the same, and one extra substring ada.

In the fifth test case, it can be proven that there is no string of length 44 which has 55 palindromic substrings.

In the sixth test case, string abcbcacbab satisfies k=3k = 3 conditions:

  • p(p( abcb )=4) = 4 . Palindromic substrings are a, b, c and bcb.
  • p(p( abcbca )=5) = 5 . Palindromic substrings are the same, and one extra substring cbc.
  • p(p( abcbcacbab )=8) = 8 . Palindromic substrings are the same, and three extra substrings cac, bab and bcacb.
首页