A12571 | Archaeology
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Alice bought a Congo Prime Video subscription and was watching a documentary on the archaeological findings from Factor's Island on Loch Katrine in Scotland. The archaeologists found a book whose age and origin are unknown. Perhaps Alice can make some sense of it?
The book contains a single string of characters "a", "b" and "c". It has been pointed out that no two consecutive characters are the same. It has also been conjectured that the string contains an unusually long subsequence that reads the same from both sides.
Help Alice verify this by finding such subsequence that contains at least half of the characters of the original string, rounded down. Note that you don't have to maximise the length of it.
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters.
The book contains a single string of characters "a", "b" and "c". It has been pointed out that no two consecutive characters are the same. It has also been conjectured that the string contains an unusually long subsequence that reads the same from both sides.
Help Alice verify this by finding such subsequence that contains at least half of the characters of the original string, rounded down. Note that you don't have to maximise the length of it.
A string $a$ is a subsequence of a string $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) characters.
输入格式
The input consists of a single string $s$ ( $2 \leq |s| \leq 10^6$ ). The string $s$ consists only of characters "a", "b", "c". It is guaranteed that no two consecutive characters are equal.
输出格式
Output a palindrome $t$ that is a subsequence of $s$ and $|t| \geq \lfloor \frac{|s|}{2} \rfloor$ .
If there are multiple solutions, you may print any of them. You don't have to maximise the length of $t$ .
If there are no solutions, output a string "IMPOSSIBLE" (quotes for clarity).
If there are multiple solutions, you may print any of them. You don't have to maximise the length of $t$ .
If there are no solutions, output a string "IMPOSSIBLE" (quotes for clarity).
输入输出样例
输入 #1
cacbac
输出 #1
aba
输入 #2
abc
输出 #2
a
输入 #3
cbacacacbcbababacbcb
输出 #3
cbaaacbcaaabc
In the first example, other valid answers include "cacac", "caac", "aca" and "ccc".
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted