QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#15400. Shuffling Cards with Problem Solver 68!

統計

Aru 热衷于玩纸牌游戏(如扑克、德州扑克、Balatro 等),并且她已经精通了洗牌的艺术,尤其是交错洗牌(riffle shuffle)。她现在正和 Mutsuki 一起玩,轮到她洗牌了!

然而,Mutsuki 知道 Aru 的洗牌技术过于完美。事实上,对于一副偶数张牌的牌组,Aru 总是执行完美的交错洗牌:她将牌组从中间平分,然后将两半交错叠放。形式化地,如果牌组由长度为 $n$ 的字符串 $s$ 表示,其中 $s_i$ 是从顶部数起的第 $i$ 张牌,那么一次交错洗牌产生的牌组为 $$s' = s_1 + s_{n/2+1} + s_2 + s_{n/2+2} + \dots + s_{n/2} + s_n.$$

Mutsuki 还知道,当拿到一副牌时,Aru 会将其交错洗牌恰好 $t$ 次。

Mutsuki 目前持有一副由 $2^k$ 张牌组成的牌组,用字符串 $d$ 表示。在将牌组交给 Aru 之前,Mutsuki 可以选择切牌,即将牌组顶部的若干张牌移到牌组底部。形式化地,她可以选择 $0$ 到 $2^k - 1$ 之间的任意整数 $m$,并产生牌组 $$d' = d_{m+1} + d_{m+2} + \dots + d_{2^k} + d_1 + d_2 + \dots + d_m.$$

在所有 $2^k$ 种可能的切牌方式中,Mutsuki 希望选择一种,使得 Aru 洗牌 $t$ 次后得到的牌组在字典序上最小。你能帮她找出这个结果吗?

输入格式

第一行包含两个整数 $k$ 和 $t$,分别表示牌组的大小参数和 Aru 洗牌的次数。

第二行包含一个长度为 $2^k$ 的小写字母字符串 $d$,表示 Mutsuki 拥有的原始牌组。

  • $1 \le k \le 18$
  • $0 \le t \le 10^9$

输出格式

输出一行字符串,表示 Mutsuki 通过切牌并让 Aru 洗牌 $t$ 次后,所能得到的字典序最小的牌组。

样例

输入 1

4 2
baaabaaabaaabaaa

输出 1

aaaaaaaaaaaabbbb

输入 2

4 999999999
abcdefghijklmnop

输出 2

acegikmobdfhjlnp

输入 3

4 17
bbcttckrdezzzbcd

输出 3

bcckdrbdbecztztz

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.