This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
def longest_palindromic_partition(s):
n = len(s)
dp = [0] * n # dp[i] stores the length of the longest palindromic partition for substring s[0:i+1]
for i in range(n):
max_len = 0
for j in range(i, -1, -1):
if s[j:i + 1] == s[i - j:i + 1]:
max_len = max(max_len, j + 1)
dp[i] = max(dp[i], max_len)
return dp[-1]
# Read the number of test cases
t = int(input())
# Process each test case
for _ in range(t):
# Read the input word
word = input().strip()
# Calculate and print the result for each test case
result = longest_palindromic_partition(word)
print(result)
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |