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 |
1 |
Incorrect |
13 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |