C - One More aab aba baa
解説
/
実行時間制限: 2 sec / メモリ制限: 1024 MB
配点 : 点
問題文
文字列 の各文字を並べ替えて作ることが可能な文字列を辞書順にすべて列挙したとき、前から 番目にくる文字列を求めてください。
「各文字を並べ替えて作ることが可能な文字列」とは?
「文字列 が文字列 の各文字を並べ替えて作ることが可能な文字列である」とは、任意の文字が文字列 と文字列 に同数含まれるということを指します。制約
- は英小文字のみからなる
- の各文字を並べ替えてできる文字列は 種類以上存在する
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1 Copy
Copy
aab 2
出力例 1 Copy
Copy
aba
文字列 aab
の各文字を並べ替えて作ることが可能な文字列は aab
, aba
, baa
の つですが、このうち辞書順で前から 番目にくるものは aba
です。
入力例 2 Copy
Copy
baba 4
出力例 2 Copy
Copy
baab
入力例 3 Copy
Copy
ydxwacbz 40320
出力例 3 Copy
Copy
zyxwdcba
Score : points
Problem Statement
Find the -th lexicographically smallest string among the strings that are permutations of a string .
What is a permutation of a string?
A string is said to be a permutation of a string when any character occurs the same number of times in and .Constraints
- consists of lowercase English letters.
- There are at least distinct strings that are permutations of .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1 Copy
Copy
aab 2
Sample Output 1 Copy
Copy
aba
There are three permutations of a string aab
: aab
, aba
, baa
. The -nd lexicographically smallest of them is aba
.
Sample Input 2 Copy
Copy
baba 4
Sample Output 2 Copy
Copy
baab
Sample Input 3 Copy
Copy
ydxwacbz 40320
Sample Output 3 Copy
Copy
zyxwdcba