Submission #916388

#TimeUsernameProblemLanguageResultExecution timeMemory
916388vjudge1Palindromic Partitions (CEOI17_palindromic)Cpython 3
0 / 100
13 ms2908 KiB
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...