A10150 | Cutting the Line
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a non-empty line $s$ and an integer $k$ . The following operation is performed with this line exactly once:
- A line is split into at most $k$ non-empty substrings, i.e. string $s$ is represented as a concatenation of a set of strings $s=t_{1}+t_{2}+...+t_{m}$ , $1<=m<=k$ .
- Some of strings $t_{i}$ are replaced by strings $t_{i}^{r}$ , that is, their record from right to left.
- The lines are concatenated back in the same order, we get string $s'=t'_{1}t'_{2}...\ t'_{m}$ , where $t'_{i}$ equals $t_{i}$ or $t_{i}^{r}$ .
Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string $s$ .
- A line is split into at most $k$ non-empty substrings, i.e. string $s$ is represented as a concatenation of a set of strings $s=t_{1}+t_{2}+...+t_{m}$ , $1<=m<=k$ .
- Some of strings $t_{i}$ are replaced by strings $t_{i}^{r}$ , that is, their record from right to left.
- The lines are concatenated back in the same order, we get string $s'=t'_{1}t'_{2}...\ t'_{m}$ , where $t'_{i}$ equals $t_{i}$ or $t_{i}^{r}$ .
Your task is to determine the lexicographically smallest string that could be the result of applying the given operation to the string $s$ .
输入格式
The first line of the input contains string $s$ ( $1<=|s|<=5000000$ ), consisting of lowercase English letters. The second line contains integer $k$ ( $1<=k<=|s|$ ) — the maximum number of parts in the partition.
输出格式
In the single line print the lexicographically minimum string $s'$ which can be obtained as a result of performing the described operation.
输入输出样例
输入 #1
aba 2
输出 #1
aab
输入 #2
aaaabacaba 2
输出 #2
aaaaabacab
输入 #3
bababa 1
输出 #3
ababab
输入 #4
abacabadabacaba 4
输出 #4
aababacabacabad
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted