Submission #998520

#TimeUsernameProblemLanguageResultExecution timeMemory
998520Ibrohim0704Palindromes (APIO14_palindrome)Cpython 3
0 / 100
221 ms131072 KiB
def largest_palindrome_occurrence(s):
    n = len(s)
    dp = [[0] * n for _ in range(n)]
    ans = 0

    for i in range(n):
        dp[i][i] = 1

    for length in range(2, n + 1):
        for i in range(n - length + 1):
            j = i + length - 1
            if s[i] == s[j]:
                if length == 2:
                    dp[i][j] = 2
                else:
                    dp[i][j] = dp[i + 1][j - 1] + 2
            else:
                dp[i][j] = max(dp[i][j - 1], dp[i + 1][j])

            ans = max(ans, dp[i][j] * length)

    return ans

# Read input
s = input().strip()

# Calculate and print the result
result = largest_palindrome_occurrence(s)
print(result)
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...