# Code

/*
_______                       ________                        _______
/ _____ \                     / ______ \                      / _____ \
/ /     \_\  _     __     _   / /      \ \   _     __     _   / /     \_\
| |          | |   |  |   | | | |        | | | |   |  |   | | | |
| |          | |   |  |   | | | |     __ | | | |   |  |   | | | |
| |       __ \  \  |  |  /  / | |     \ \| | \  \  |  |  /  / | |       __
\ \_____/ /  \  \/ /\ \/  /   \ \_____\  /   \  \/ /\ \/  /   \ \_____/ /
\_______/    \___/  \___/     \______/\__\   \___/  \___/     \_______/
*/
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

const int N = 5000;

int n, k;

char st[N * 2 + 50];

int Cmp(int a, int b)
{
for (int i = 1; i <= n; i++)
{
if (st[a - i + 1] < st[b - i + 1]) return 1;
if (st[a - i + 1] > st[b - i + 1]) return 2;
}
return 0;
}

int main()
{
scanf("%d%d", &n, &k);
scanf("%s", st + 1);
for (int i = 1; i <= n; i++) st[n * 2 - i + 1] = st[i];
int pos = n;
for (int i = n + 1; i <= n * 2; i++) if (Cmp(i, pos) == 1) pos = i;
k--;
int len = 1;
while (st[pos - len] == st[pos] && len + 1 <= n) len++;
int tmp = len;
int ned = 0;
while (len < n && ned + 1 <= k) len *= 2, ned++;
if (len >= n) for (int i = 1; i <= n; i++) putchar(st[pos]);
else
{
for (int i = 1; i <= len; i++) putchar(st[pos]);
for (int i = 1; i <= n - len; i++) putchar(st[pos - tmp + 1 - i]);
}
return 0;
}
posted @ 2020-11-11 19:06  Tian-Xing  阅读(69)  评论(0编辑  收藏  举报