APIO '14 P1 - Palindromes

View as PDF

Submit solution

Points: 25 (partial)
Time limit: 0.6s
Memory limit: 128M

Problem types

You are given a string of lowercase Latin letters. Let us define a substring's "occurrence value" as the number of the substring occurrences in the string multiplied by the length of the substring. For a given string find the largest occurrence value of palindromic substrings.

Notes

|s| is the length of string s.
A substring of string s1s2s|s| is any non-empty string sisi+1sj, where 1ij|s|. Any string is also its own substring.
A string is called palindromic, if it reads the same in either direction: from left to right and from right to left.

Input Specification

The only line of input contains a non-empty string of lowercase Latin letters (a-z).

Output Specification

Output one integer – the largest occurrence value of palindromic substrings.

Sample Input 1

Copy
abacaba

Sample Output 1

Copy
7

Explanation for Sample Output 1

There are seven palindromic substrings a, b, c, aba, aca, bacab, abacaba.

  • a has 4 occurrences in the given string, its occurrence value is 4×1=4
  • b has 2 occurrences in the given string, its occurrence value is 2×1=2
  • c has 1 occurrence in the given string, its occurrence value is 1×1=1
  • aba has 2 occurrences in the given string, its occurrence value is 2×3=6
  • aca has 1 occurrence in the given string, its occurrence value is 1×3=3
  • bacab has 1 occurrence in the given string, its occurrence value is 1×5=5
  • abacaba has 1 occurrence in the given string, its occurrence value is 1×7=7

So, the largest occurrence value of palindromic substrings is 7.

Sample Input 2

Copy
www

Sample Output 2

Copy
4

Scoring

Subtask 1 (points: 8)

1|s|100

Subtask 2 (points: 15)

1|s|1000

Subtask 3 (points: 24)

1|s|10000

Subtask 4 (points: 26)

1|s|100000

Subtask 5 (points: 27)

1|s|300000


Comments

There are no comments at the moment.