102152: [AtCoder]ABC215 C - One More aab aba baa
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Score : $300$ points
Problem Statement
Find the $K$-th lexicographically smallest string among the strings that are permutations of a string $S$.
What is a permutation of a string?
A string $A$ is said to be a permutation of a string $B$ when any character occurs the same number of times in $A$ and $B$.Constraints
- $1 \le |S| \le 8$
- $S$ consists of lowercase English letters.
- There are at least $K$ distinct strings that are permutations of $S$.
Input
Input is given from Standard Input in the following format:
$S$ $K$
Output
Print the answer.
Sample Input 1
aab 2
Sample Output 1
aba
There are three permutations of a string aab
: $\{$ aab
, aba
, baa
$\}$. The $2$-nd lexicographically smallest of them is aba
.
Sample Input 2
baba 4
Sample Output 2
baab
Sample Input 3
ydxwacbz 40320
Sample Output 3
zyxwdcba
Input
Output
分数:300分
部分
问题描述
找出字符串S的所有排列中字典序第K小的字符串。
部分
约束条件
* $1 \le |S| \le 8$
* 字符串S由小写英文字母组成。
* 至少有K个不同的字符串是S的排列。
输入输出格式
输入格式
输入格式如下:
$S$ $K$
输出格式
输出答案。
样例输入1
aab 2
样例输出1
aba
字符串的排列有三种:$\{$
什么是字符串的排列?
当字符串A和B中的任意字符出现次数相同时,称字符串A是字符串B的排列。aab
,aba
,baa
$\}$。其中字典序第2小的字符串是aba
。
样例输入2
baba 4
样例输出2
baab
样例输入3
ydxwacbz 40320
样例输出3
zyxwdcba