A16431 | Palindromic Problem
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ of length $n$ , consisting of lowercase Latin letters.
You are allowed to replace at most one character in the string with an arbitrary lowercase Latin letter.
Print the lexicographically minimal string that can be obtained from the original string and contains the maximum number of palindromes as substrings. Note that if a palindrome appears more than once as a substring, it is counted the same number of times it appears.
The string $a$ is lexicographically smaller than the string $b$ if and only if one of the following holds:
- $a$ is a prefix of $b$ , but $a \ne b$ ;
- in the first position where $a$ and $b$ are different, the string $a$ contains a letter that appears earlier in the alphabet than the corresponding letter in $b$ .
You are allowed to replace at most one character in the string with an arbitrary lowercase Latin letter.
Print the lexicographically minimal string that can be obtained from the original string and contains the maximum number of palindromes as substrings. Note that if a palindrome appears more than once as a substring, it is counted the same number of times it appears.
The string $a$ is lexicographically smaller than the string $b$ if and only if one of the following holds:
- $a$ is a prefix of $b$ , but $a \ne b$ ;
- in the first position where $a$ and $b$ are different, the string $a$ contains a letter that appears earlier in the alphabet than the corresponding letter in $b$ .
输入格式
The first line contains one integer $n$ ( $1 \leq n \leq 3 \cdot 10^5$ ) — the number of characters in the string.
The second line contains the string $s$ itself, consisting of exactly $n$ lowercase Latin letters.
The second line contains the string $s$ itself, consisting of exactly $n$ lowercase Latin letters.
输出格式
In the first line, print one integer — the maximum number of palindromic substrings that can be obtained using the operation described in the statement at most once.
In the second line, print the string that can be obtained from $s$ and has the maximum possible number of palindromic substrings. If there are multiple answers, print the lexicographically smallest one.
In the second line, print the string that can be obtained from $s$ and has the maximum possible number of palindromic substrings. If there are multiple answers, print the lexicographically smallest one.
输入输出样例
输入 #1
5 aabaa
输出 #1
15 aaaaa
输入 #2
5 aaaaa
输出 #2
15 aaaaa
输入 #3
4 awoo
输出 #3
7 aooo
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted