Fun with Palindromes
Problem : 1
Unique Palindromes. https://codeforces.com/contest/1823/problem/D
Idea: Constructive
Problem : 2
Petr Petya and Palindrome. https://codeforces.com/problemset/problem/1808/D
Idea: Contribution to Answer Trick
- Given an odd integer k find sum of palindromicity across all substring of s of length of k.
- Palindromicity is minimum number of characters to replace to make the string palindrome.
Observations
- For odd palindromes characters in indices match with indices of same parity.
- Separate out all the even and odd indices.
- Instead of finding the good contributions i.e no of replacements. Lets find number of non-replacements.
- So for non replacements the characters are all same.
- So take all same characters for a particular parity together.
- [a(3),a(5),a(13),a(15),a(17)]
- For each i. Calculate no of non-replacement (non-contribution to Sum) for all the j < i.
- Findout the inequalities and solve using ranges method, upperbound and lowerbound.