CF2172H.Shuffling Cards with Problem Solver 68!
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Aru loves playing card games (Poker, Texas hold 'em, Balatro, etc.) and she has perfected the art of shuffling cards, especially the riffle shuffle. She is playing with Mutsuki now, and it's her turn to shuffle the cards!
However, Mutsuki knows that Aru is too perfect with her shuffling game. In fact, given a deck with an even number of cards, Aru always performs a perfect riffle: she cuts the deck evenly and interleaves the two halves. Formally, if the deck is represented by a string s of length n, where si is the i-th card from the top, one riffle produces the deck $$s^\prime = s_1 + s_{n/2 + 1} + s_2 + s_{n/2 + 2} + \ldots + s_{n/2} + s_{n}.$$ Mutsuki also knows that when handed a deck of cards, Aru will riffle it exactly t times.
Mutsuki currently holds a deck of 2k cards, represented by a string d. Before giving the deck to Aru, Mutsuki can choose to cut the deck, by moving some number of cards from the top to the bottom of the deck. Formally, she can choose any m from 0 to 2k−1, and produce the deck $$d^\prime = d_{m + 1} + d_{m + 2} + \ldots + d_{2^k} + d_1 + d_2 + \ldots + d_m.$$
Among all 2k possible cuts, Mutsuki wants to choose the one that results in the lexicographically smallest deck after Aru riffles it t times. Can you figure this out for her?
Aru 喜欢玩纸牌游戏(如扑克、德州扑克、Balatro 等),并且她已将洗牌技艺修炼至炉火纯青,尤其是“鸽尾式洗牌”(riffle shuffle)。此刻她正与睦月一起玩牌,轮到她来洗牌了!
然而,睦月深知 Aru 的洗牌技术太过完美。事实上,对于一张拥有偶数张牌的牌堆,Aru 总是执行一次“完美鸽尾式洗牌”:她将牌堆从正中间均分为两半,然后将这两半严格交错合并。形式化地说,若牌堆用长度为 n 的字符串 s 表示,其中 si 表示从上往下数第 i 张牌,则一次鸽尾式洗牌后得到的新牌堆为
s^\\prime = s\_1 + s\_{n/2 + 1} + s\_2 + s\_{n/2 + 2} + \\ldots + s\_{n/2} + s\_{n}.睦月还知道,每当她把一副牌交给 Aru 时,Aru 都会恰好执行 t 次鸽尾式洗牌。
目前睦月手中持有一副共 2k 张牌的牌堆,用字符串 d 表示。在将这副牌交给 Aru 之前,睦月可以先对牌堆进行一次“切牌”操作:即把顶部若干张牌移到牌堆底部。形式化地说,她可任选一个整数 m(满足 0lemle2k−1),从而得到新牌堆
d^\\prime = d\_{m + 1} + d\_{m + 2} + \\ldots + d\_{2^k} + d\_1 + d\_2 + \\ldots + d\_m.在全部 2k 种可能的切牌方式中,睦月希望选出一种,使得 Aru 对其执行 t 次鸽尾式洗牌后所得牌堆的字典序最小。你能帮她找出这个最优方案吗?
输入格式
The first line contains two integers k and t, representing the size parameter of the deck, and the number of times Aru will riffle the deck, respectively.
The second line contains a string d of 2k lowercase characters, representing the original deck of cards that Mutsuki has.
- 1≤k≤18
- 0≤t≤109
第一行包含两个整数 k 和 t,分别表示牌组的尺寸参数和阿鲁将进行的洗牌次数。
第二行包含一个长度为 2k 的字符串 d,由小写字母组成,表示睦月原有的牌组。
- 1≤k≤18
- 0≤t≤109
输出格式
Print a string in one line, representing the lexicographically smallest deck of cards that Mutsuki can produce, by first cutting the deck and letting Aru riffle it t times.
在一行中输出一个字符串,表示 Mutsuki 通过先切牌,再让 Aru 进行 t 次洗牌后所能得到的字典序最小的扑克牌序列。
输入输出样例
输入#1
4 2 baaabaaabaaabaaa
输出#1
aaaaaaaaaaaabbbb
输入#2
4 999999999 abcdefghijklmnop
输出#2
acegikmobdfhjlnp
输入#3
4 17 bbcttckrdezzzbcd
输出#3
bcckdrbdbecztztz
输入解题思路,AI测评打分。不知道怎么写?