이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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... |