CF1367D.Task On The Board

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Polycarp wrote on the board a string ss containing only lowercase Latin letters ('a'-'z'). This string is known for you and given in the input.

After that, he erased some letters from the string ss, and he rewrote the remaining letters in any order. As a result, he got some new string tt. You have to find it with some additional information.

Suppose that the string tt has length mm and the characters are numbered from left to right from 11 to mm. You are given a sequence of mm integers: b1,b2,…,bmb_1, b_2, \ldots, b_m, where bib_i is the sum of the distances ∣i−j∣|i-j| from the index ii to all such indices jj that tj>tit_j \gt t_i (consider that 'a'<'b'<...<'z'). In other words, to calculate bib_i, Polycarp finds all such indices jj that the index jj contains a letter that is later in the alphabet than tit_i and sums all the values ∣i−j∣|i-j|.

For example, if tt = "abzb", then:

  • since t1t_1='a', all other indices contain letters which are later in the alphabet, that is: b1=∣1−2∣+∣1−3∣+∣1−4∣=1+2+3=6b_1=|1-2|+|1-3|+|1-4|=1+2+3=6;
  • since t2t_2='b', only the index j=3j=3 contains the letter, which is later in the alphabet, that is: b2=∣2−3∣=1b_2=|2-3|=1;
  • since t3t_3='z', then there are no indexes jj such that tj>tit_j \gt t_i, thus b3=0b_3=0;
  • since t4t_4='b', only the index j=3j=3 contains the letter, which is later in the alphabet, that is: b4=∣4−3∣=1b_4=|4-3|=1.

Thus, if tt = "abzb", then b=[6,1,0,1]b=[6,1,0,1].

Given the string ss and the array bb, find any possible string tt for which the following two requirements are fulfilled simultaneously:

  • tt is obtained from ss by erasing some letters (possibly zero) and then writing the rest in any order;
  • the array, constructed from the string tt according to the rules above, equals to the array bb specified in the input data.

波利卡普在黑板上写了一个仅包含小写拉丁字母('a'–'z')的字符串 ss。该字符串已知,且作为输入给出。

随后,他从字符串 ss 中擦除了若干字母,并将剩余字母以任意顺序重新书写,从而得到一个新字符串 tt。你需要根据一些附加信息找出这个字符串 tt。

假设字符串 tt 的长度为 mm,其字符从左到右编号为 11 到 mm。你将获得一个由 mm 个整数组成的序列:b1,b2,…,bmb_1, b_2, \ldots, b_m,其中 bib_i 表示所有满足 tj>tit_j > t_i 的下标 jj 到下标 ii 的距离之和 ∣i−j∣|i-j|(约定 'a' < 'b' < ... < 'z')。换言之,为计算 bib_i,波利卡普找出所有满足 tjt_j 在字母表中位于 tit_i 之后的下标 jj,并将所有 ∣i−j∣|i-j| 的值相加。

例如,若 t=“abzb”t = \text{``abzb''},则:

  • 由于 t1=’a’t_1 = \text{'a'},其余所有下标处的字母均在字母表中位于 'a' 之后,即:b1=∣1−2∣+∣1−3∣+∣1−4∣=1+2+3=6b_1 = |1-2| + |1-3| + |1-4| = 1 + 2 + 3 = 6;
  • 由于 t2=’b’t_2 = \text{'b'},仅下标 j=3j = 3 处的字母在字母表中位于 'b' 之后,即:b2=∣2−3∣=1b_2 = |2-3| = 1;
  • 由于 t3=’z’t_3 = \text{'z'},不存在满足 tj>tit_j > t_i 的下标 jj,故 b3=0b_3 = 0;
  • 由于 t4=’b’t_4 = \text{'b'},仅下标 j=3j = 3 处的字母在字母表中位于 'b' 之后,即:b4=∣4−3∣=1b_4 = |4-3| = 1。

因此,若 t=“abzb”t = \text{``abzb''},则 b=[6,1,0,1]b = [6,1,0,1]。

给定字符串 ss 和数组 bb,请找出任意一个可能的字符串 tt,使得以下两个条件同时成立:

  • tt 是通过从 ss 中擦除若干字母(可能为零个)后,将剩余字母以任意顺序重排而得到的;
  • 按照上述规则由字符串 tt 构造出的数组等于输入中指定的数组 bb。

输入格式

The first line contains an integer qq (1≤q≤1001 \le q \le 100) — the number of test cases in the test. Then qq test cases follow.

Each test case consists of three lines:

  • the first line contains string ss, which has a length from 11 to 5050 and consists of lowercase English letters;
  • the second line contains positive integer mm (1≤m≤∣s∣1 \le m \le |s|), where ∣s∣|s| is the length of the string ss, and mm is the length of the array bb;
  • the third line contains the integers b1,b2,…,bmb_1, b_2, \dots, b_m (0≤bi≤12250 \le b_i \le 1225).

It is guaranteed that in each test case an answer exists.

第一行包含一个整数 qq(1≤q≤1001 \le q \le 100),表示测试用例的数量。随后是 qq 个测试用例。

每个测试用例由三行组成:

  • 第一行包含字符串 ss,其长度为 11 到 5050,且仅由小写英文字母组成;
  • 第二行包含正整数 mm(1≤m≤∣s∣1 \le m \le |s|),其中 ∣s∣|s| 表示字符串 ss 的长度,mm 为数组 bb 的长度;
  • 第三行包含整数 b1,b2,…,bmb_1, b_2, \dots, b_m(0≤bi≤12250 \le b_i \le 1225)。

保证每个测试用例均存在解。

输出格式

Output qq lines: the kk-th of them should contain the answer (string tt) to the kk-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any.

输出 qq 行:第 kk 行应包含第 kk 个测试用例的答案(字符串 tt)。保证每个测试用例均存在答案。若存在多个答案,输出任意一个即可。

输入输出样例

  • 输入#1

    4
    abac
    3
    2 1 0
    abc
    1
    0
    abba
    3
    1 0 1
    ecoosdcefr
    10
    38 13 24 14 11 5 3 24 17 0

    输出#1

    aac
    b
    aba
    codeforces

说明/提示

In the first test case, such strings tt are suitable: "aac', "aab".

In the second test case, such trings tt are suitable: "a", "b", "c".

In the third test case, only the string tt equals to "aba" is suitable, but the character 'b' can be from the second or third position.

在第一个测试用例中,满足条件的字符串 tt 有:"aac"、"aab"。

在第二个测试用例中,满足条件的字符串 tt 有:"a"、"b"、"c"。

在第三个测试用例中,唯一满足条件的字符串 tt 是 "aba",但其中的字符 'b' 可以来自原字符串的第二个或第三个位置。

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

首页