CF1706A.Another String Minimization Problem

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a sequence a1,a2,…,ana_1, a_2, \ldots, a_n of length nn, consisting of integers between 11 and mm. You also have a string ss, consisting of mm characters B.

You are going to perform the following nn operations.

  • At the ii-th (1≤i≤n1 \le i \le n) operation, you replace either the aia_i-th or the (m+1−ai)(m + 1 - a_i)-th character of ss with A. You can replace the character at any position multiple times through the operations.

Find the lexicographically smallest string you can get after these operations.

A string xx is lexicographically smaller than a string yy of the same length if and only if in the first position where xx and yy differ, the string xx has a letter that appears earlier in the alphabet than the corresponding letter in yy.

你有一个长度为 nn 的序列 a1,a2,…,ana_1, a_2, \ldots, a_n,其中每个元素均为 11 到 mm 之间的整数。你还有一条长度为 mm 的字符串 ss,其所有字符均为 B。

接下来你将执行 nn 次操作。

  • 在第 ii 次操作(1≤i≤n1 \le i \le n)中,你需要将 ss 的第 aia_i 个字符或第 (m+1−ai)(m + 1 - a_i) 个字符替换为 A。同一位置的字符可在不同操作中被多次替换。

求经过这些操作后能得到的字典序最小的字符串。

字符串 xx 的字典序小于等长字符串 yy,当且仅当在 xx 与 yy 首次出现差异的位置上,xx 中的字母在字母表中早于 yy 中对应位置的字母。

输入格式

The first line contains the number of test cases tt (1≤t≤20001 \le t \le 2000).

The first line of each test case contains two integers nn and mm (1≤n,m≤501 \le n, m \le 50) — the length of the sequence aa and the length of the string ss respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤m1 \le a_i \le m) — the sequence aa.

第一行包含测试用例的数量 tt(1≤t≤20001 \le t \le 2000)。

每个测试用例的第一行包含两个整数 nn 和 mm(1≤n,m≤501 \le n, m \le 50),分别表示序列 aa 的长度和字符串 ss 的长度。

每个测试用例的第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤m1 \le a_i \le m),即序列 aa。

输出格式

For each test case, print a string of length mm — the lexicographically smallest string you can get. Each character of the string should be either capital English letter A or capital English letter B.

对于每个测试用例,输出一个长度为 mm 的字符串——你能得到的字典序最小的字符串。该字符串的每个字符必须是大写英文字母 A 或大写英文字母 B。

输入输出样例

  • 输入#1

    6
    4 5
    1 1 3 1
    1 5
    2
    4 1
    1 1 1 1
    2 4
    1 3
    2 7
    7 5
    4 5
    5 5 3 5

    输出#1

    ABABA
    BABBB
    A
    AABB
    ABABBBB
    ABABA

说明/提示

In the first test case, the sequence a=[1,1,3,1]a = [1, 1, 3, 1]. One of the possible solutions is the following.

  • At the 11-st operation, you can replace the 11-st character of ss with A. After it, ss becomes ABBBB.
  • At the 22-nd operation, you can replace the 55-th character of ss with A (since m+1−a2=5m+1-a_2=5). After it, ss becomes ABBBA.
  • At the 33-rd operation, you can replace the 33-rd character of ss with A. After it, ss becomes ABABA.
  • At the 44-th operation, you can replace the 11-st character of ss with A. After it, ss remains equal to ABABA.

The resulting string is ABABA. It is impossible to produce a lexicographically smaller string.

In the second test case, you are going to perform only one operation. You can replace either the 22-nd character or 44-th character of ss with A. You can get strings BABBB and BBBAB after the operation. The string BABBB is the lexicographically smallest among these strings.

In the third test case, the only string you can get is A.

In the fourth test case, you can replace the 11-st and 22-nd characters of ss with A to get AABB.

In the fifth test case, you can replace the 11-st and 33-rd characters of ss with A to get ABABBBB.

在第一个测试用例中,序列 a=[1,1,3,1]a = [1, 1, 3, 1]。其中一种可能的解法如下:

  • 在第 11 次操作中,你可以将 ss 的第 11 个字符替换为 A。操作后,ss 变为 ABBBB。
  • 在第 22 次操作中,你可以将 ss 的第 55 个字符替换为 A(因为 m+1−a2=5m+1-a_2=5)。操作后,ss 变为 ABBBA。
  • 在第 33 次操作中,你可以将 ss 的第 33 个字符替换为 A。操作后,ss 变为 ABABA。
  • 在第 44 次操作中,你可以将 ss 的第 11 个字符替换为 A。操作后,ss 仍为 ABABA。

最终得到的字符串是 ABABA。无法生成字典序更小的字符串。

在第二个测试用例中,你仅执行一次操作。你可以将 ss 的第 22 个字符或第 44 个字符替换为 A。操作后可分别得到字符串 BABBB 和 BBBAB。其中,BABBB 是这些字符串中字典序最小的。

在第三个测试用例中,你能得到的唯一字符串是 A。

在第四个测试用例中,你可以将 ss 的第 11 个和第 22 个字符替换为 A,从而得到 AABB。

在第五个测试用例中,你可以将 ss 的第 11 个和第 33 个字符替换为 A,从而得到 ABABBBB。

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

首页