結果

問題 No.273 回文分解
ユーザー tookunn_1213tookunn_1213
提出日時 2016-07-06 23:04:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 606 bytes
コンパイル時間 154 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 15,988 KB
最終ジャッジ日時 2023-08-25 01:31:35
合計ジャッジ時間 4,801 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
15,988 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 15 ms
7,844 KB
testcase_04 AC 14 ms
7,856 KB
testcase_05 AC 60 ms
7,844 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 17 ms
7,912 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 113 ms
7,856 KB
testcase_15 AC 14 ms
7,956 KB
testcase_16 AC 15 ms
7,912 KB
testcase_17 AC 14 ms
7,856 KB
testcase_18 WA -
testcase_19 AC 17 ms
7,860 KB
testcase_20 AC 18 ms
7,960 KB
testcase_21 AC 19 ms
7,868 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 17 ms
7,856 KB
testcase_25 AC 23 ms
7,868 KB
testcase_26 TLE -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

S = input()
N = len(S)
ans = 0
def isPalindrome(p):
	s,t,c = 0,len(p) - 1,0
	while s < t and p[s] == p[t]:
		s,t,c= s + 1,t - 1,c + 2
	if s == t and p[s] == p[t]:
		c += 1
	return c == len(p)
def palindrome(p):
	n = len(p)

	if n == 1:
		return True
	for i in range(n - 1):
		for j in range(i + 1,n):
			if isPalindrome(p[i:j + 1]):
				return True
	return False

def dfs(n,m):
	if n == N:
		return 0
	ret = 0
	for i in range(n,N if m >= 1 else N - 1):
		if isPalindrome(S[n:i + 1]) and palindrome(S[i::]):
			d = dfs(i + 1,m + 1)
			ret = max(i + 1 - n,ret)
			ret = max(ret,d)
	return ret
print(dfs(0,0))
0