CF1367D.Task On The Board
普及+/提高
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Polycarp wrote on the board a string s 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 s, and he rewrote the remaining letters in any order. As a result, he got some new string t. You have to find it with some additional information.
Suppose that the string t has length m and the characters are numbered from left to right from 1 to m. You are given a sequence of m integers: b1,b2,…,bm, where bi is the sum of the distances ∣i−j∣ from the index i to all such indices j that tj>ti (consider that 'a'<'b'<...<'z'). In other words, to calculate bi, Polycarp finds all such indices j that the index j contains a letter that is later in the alphabet than ti and sums all the values ∣i−j∣.
For example, if t = "abzb", then:
- since t1='a', all other indices contain letters which are later in the alphabet, that is: b1=∣1−2∣+∣1−3∣+∣1−4∣=1+2+3=6;
- since t2='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b2=∣2−3∣=1;
- since t3='z', then there are no indexes j such that tj>ti, thus b3=0;
- since t4='b', only the index j=3 contains the letter, which is later in the alphabet, that is: b4=∣4−3∣=1.
Thus, if t = "abzb", then b=[6,1,0,1].
Given the string s and the array b, find any possible string t for which the following two requirements are fulfilled simultaneously:
- t is obtained from s by erasing some letters (possibly zero) and then writing the rest in any order;
- the array, constructed from the string t according to the rules above, equals to the array b specified in the input data.
波利卡普在黑板上写了一个仅包含小写拉丁字母('a'–'z')的字符串 s。该字符串已知,且作为输入给出。
随后,他从字符串 s 中擦除了若干字母,并将剩余字母以任意顺序重新书写,从而得到一个新字符串 t。你需要根据一些附加信息找出这个字符串 t。
假设字符串 t 的长度为 m,其字符从左到右编号为 1 到 m。你将获得一个由 m 个整数组成的序列:b1,b2,…,bm,其中 bi 表示所有满足 tj>ti 的下标 j 到下标 i 的距离之和 ∣i−j∣(约定 'a' < 'b' < ... < 'z')。换言之,为计算 bi,波利卡普找出所有满足 tj 在字母表中位于 ti 之后的下标 j,并将所有 ∣i−j∣ 的值相加。
例如,若 t=“abzb”,则:
- 由于 t1=’a’,其余所有下标处的字母均在字母表中位于 'a' 之后,即:b1=∣1−2∣+∣1−3∣+∣1−4∣=1+2+3=6;
- 由于 t2=’b’,仅下标 j=3 处的字母在字母表中位于 'b' 之后,即:b2=∣2−3∣=1;
- 由于 t3=’z’,不存在满足 tj>ti 的下标 j,故 b3=0;
- 由于 t4=’b’,仅下标 j=3 处的字母在字母表中位于 'b' 之后,即:b4=∣4−3∣=1。
因此,若 t=“abzb”,则 b=[6,1,0,1]。
给定字符串 s 和数组 b,请找出任意一个可能的字符串 t,使得以下两个条件同时成立:
- t 是通过从 s 中擦除若干字母(可能为零个)后,将剩余字母以任意顺序重排而得到的;
- 按照上述规则由字符串 t 构造出的数组等于输入中指定的数组 b。
输入格式
The first line contains an integer q (1≤q≤100) — the number of test cases in the test. Then q test cases follow.
Each test case consists of three lines:
- the first line contains string s, which has a length from 1 to 50 and consists of lowercase English letters;
- the second line contains positive integer m (1≤m≤∣s∣), where ∣s∣ is the length of the string s, and m is the length of the array b;
- the third line contains the integers b1,b2,…,bm (0≤bi≤1225).
It is guaranteed that in each test case an answer exists.
第一行包含一个整数 q(1≤q≤100),表示测试用例的数量。随后是 q 个测试用例。
每个测试用例由三行组成:
- 第一行包含字符串 s,其长度为 1 到 50,且仅由小写英文字母组成;
- 第二行包含正整数 m(1≤m≤∣s∣),其中 ∣s∣ 表示字符串 s 的长度,m 为数组 b 的长度;
- 第三行包含整数 b1,b2,…,bm(0≤bi≤1225)。
保证每个测试用例均存在解。
输出格式
Output q lines: the k-th of them should contain the answer (string t) to the k-th test case. It is guaranteed that an answer to each test case exists. If there are several answers, output any.
输出 q 行:第 k 行应包含第 k 个测试用例的答案(字符串 t)。保证每个测试用例均存在答案。若存在多个答案,输出任意一个即可。
输入输出样例
输入#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 t are suitable: "aac', "aab".
In the second test case, such trings t are suitable: "a", "b", "c".
In the third test case, only the string t equals to "aba" is suitable, but the character 'b' can be from the second or third position.
在第一个测试用例中,满足条件的字符串 t 有:"aac"、"aab"。
在第二个测试用例中,满足条件的字符串 t 有:"a"、"b"、"c"。
在第三个测试用例中,唯一满足条件的字符串 t 是 "aba",但其中的字符 'b' 可以来自原字符串的第二个或第三个位置。
输入解题思路,AI测评打分。不知道怎么写?