A1331 | [COCI-2015_2016-olympiad]#2 Palinilap
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
A palindrome is a word that reads the same backwards as forwards. For example, “a”, “abba” and “anavolimilovana” are palindromes A sample is a string of one or more lower case letters of the English alphabet, and the weight of a sample is the number of its substrings (words) that are palindromes, counting each word occurrence separately.
More precisely, let w be a sample of length n. The word wa,b is obtained by taking all characters from position a to position b in sample w. The weight of sample w is defined as the number of different pairs of integers a, b (1 ≤ a ≤ b ≤ n) such that the word wa,b is a palindrome.
You are given the sample w. It can either be left unchanged, or exactly one position can be chosen and the letter on that position arbitrarily changed. Find the maximal possible sample weight that can be obtained as described above.
More precisely, let w be a sample of length n. The word wa,b is obtained by taking all characters from position a to position b in sample w. The weight of sample w is defined as the number of different pairs of integers a, b (1 ≤ a ≤ b ≤ n) such that the word wa,b is a palindrome.
You are given the sample w. It can either be left unchanged, or exactly one position can be chosen and the letter on that position arbitrarily changed. Find the maximal possible sample weight that can be obtained as described above.
输入格式
The first line of input contains the given sample w – a string of lower case letters of the English alphabet.
输出格式
You must output the required maximal possible weight.
输入输出样例
输入 #1
aaaa
输出 #1
10
输入 #2
baccb
输出 #2
9
输入 #3
slavko
输出 #3
7
Let n be the length of the given sample.
Subtask Score Limitations
1 17 1 ≤ n ≤ 100
2 37 101 ≤ n ≤ 5 000
3 46 5001 ≤ n ≤ 100 000
Clarification of the first example: Each substring from the sample already is a palindrome, so it is
best left unchanged.
Clarification of the second example: If we change the second letter of the sample to “c”, we will
get the sample “bcccb” with a weight of 9.
Subtask Score Limitations
1 17 1 ≤ n ≤ 100
2 37 101 ≤ n ≤ 5 000
3 46 5001 ≤ n ≤ 100 000
Clarification of the first example: Each substring from the sample already is a palindrome, so it is
best left unchanged.
Clarification of the second example: If we change the second letter of the sample to “c”, we will
get the sample “bcccb” with a weight of 9.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted