A13397 | Phoenix and Distribution
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Phoenix has a string $s$ consisting of lowercase Latin letters. He wants to distribute all the letters of his string into $k$ non-empty strings $a_1, a_2, \dots, a_k$ such that every letter of $s$ goes to exactly one of the strings $a_i$ . The strings $a_i$ do not need to be substrings of $s$ . Phoenix can distribute letters of $s$ and rearrange the letters within each string $a_i$ however he wants.
For example, if $s = $ baba and $k=2$ , Phoenix may distribute the letters of his string in many ways, such as:
- ba and ba
- a and abb
- ab and ab
- aa and bb
But these ways are invalid:
- baa and ba
- b and ba
- baba and empty string ( $a_i$ should be non-empty)
Phoenix wants to distribute the letters of his string $s$ into $k$ strings $a_1, a_2, \dots, a_k$ to minimize the lexicographically maximum string among them, i. e. minimize $max(a_1, a_2, \dots, a_k)$ . Help him find the optimal distribution and print the minimal possible value of $max(a_1, a_2, \dots, a_k)$ .
String $x$ is lexicographically less than string $y$ if either $x$ is a prefix of $y$ and $x \ne y$ , or there exists an index $i$ ( $1 \le i \le min(|x|, |y|))$ such that $x_i$ < $y_i$ and for every $j$ $(1 \le j < i)$ $x_j = y_j$ . Here $|x|$ denotes the length of the string $x$ .
For example, if $s = $ baba and $k=2$ , Phoenix may distribute the letters of his string in many ways, such as:
- ba and ba
- a and abb
- ab and ab
- aa and bb
But these ways are invalid:
- baa and ba
- b and ba
- baba and empty string ( $a_i$ should be non-empty)
Phoenix wants to distribute the letters of his string $s$ into $k$ strings $a_1, a_2, \dots, a_k$ to minimize the lexicographically maximum string among them, i. e. minimize $max(a_1, a_2, \dots, a_k)$ . Help him find the optimal distribution and print the minimal possible value of $max(a_1, a_2, \dots, a_k)$ .
String $x$ is lexicographically less than string $y$ if either $x$ is a prefix of $y$ and $x \ne y$ , or there exists an index $i$ ( $1 \le i \le min(|x|, |y|))$ such that $x_i$ < $y_i$ and for every $j$ $(1 \le j < i)$ $x_j = y_j$ . Here $|x|$ denotes the length of the string $x$ .
输入格式
The input consists of multiple test cases. The first line contains an integer $t$ ( $1 \le t \le 1000$ ) — the number of test cases. Each test case consists of two lines.
The first line of each test case consists of two integers $n$ and $k$ ( $1 \le k \le n \le 10^5$ ) — the length of string $s$ and the number of non-empty strings, into which Phoenix wants to distribute letters of $s$ , respectively.
The second line of each test case contains a string $s$ of length $n$ consisting only of lowercase Latin letters.
It is guaranteed that the sum of $n$ over all test cases is $\le 10^5$ .
The first line of each test case consists of two integers $n$ and $k$ ( $1 \le k \le n \le 10^5$ ) — the length of string $s$ and the number of non-empty strings, into which Phoenix wants to distribute letters of $s$ , respectively.
The second line of each test case contains a string $s$ of length $n$ consisting only of lowercase Latin letters.
It is guaranteed that the sum of $n$ over all test cases is $\le 10^5$ .
输出格式
Print $t$ answers — one per test case. The $i$ -th answer should be the minimal possible value of $max(a_1, a_2, \dots, a_k)$ in the $i$ -th test case.
输入输出样例
输入 #1
6 4 2 baba 5 2 baacb 5 3 baacb 5 3 aaaaa 6 4 aaxxzz 7 1 phoenix
输出 #1
ab abbc b aa x ehinopx
In the first test case, one optimal solution is to distribute baba into ab and ab.
In the second test case, one optimal solution is to distribute baacb into abbc and a.
In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.
In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.
In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.
In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.
In the second test case, one optimal solution is to distribute baacb into abbc and a.
In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.
In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.
In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.
In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted