6878.All Palindromes

Time Limit: 1s Memory Limit: 512MB

Given a string, calculate for each position the length of the longest palindrome that ends at that position.

Input Format(From the terminal/stdin)

The only line contains a string of length $n$ . Each character is one of a–z.

  • $1 \le n \le 2 \cdot 10^5$

Output Format(To the terminal/stdout)

Print $n$ numbers: the length of each palindrome.

Sample Input

Copy
ababbababaa
           \n

Sample Output

Copy
1 1 3 3 2 4 6 8 5 5 2
 · · · · · · · · · · \n
Source: CSES, String Algorithms, 3138

Submit

请先 登录

© 2025 FAQs