結果
問題 | No.2204 Palindrome Splitting (No Rearrangement ver.) |
ユーザー | LyricalMaestro |
提出日時 | 2024-07-28 02:11:44 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,281 bytes |
コンパイル時間 | 508 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 564,916 KB |
最終ジャッジ日時 | 2024-07-28 02:12:38 |
合計ジャッジ時間 | 52,274 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 40 ms
57,856 KB |
testcase_01 | AC | 39 ms
52,224 KB |
testcase_02 | AC | 47 ms
60,160 KB |
testcase_03 | AC | 1,181 ms
76,868 KB |
testcase_04 | AC | 317 ms
76,280 KB |
testcase_05 | AC | 202 ms
76,416 KB |
testcase_06 | TLE | - |
testcase_07 | AC | 1,767 ms
77,456 KB |
testcase_08 | AC | 1,554 ms
77,312 KB |
testcase_09 | AC | 1,661 ms
79,828 KB |
testcase_10 | AC | 1,927 ms
77,568 KB |
testcase_11 | AC | 1,569 ms
77,392 KB |
testcase_12 | AC | 1,973 ms
77,740 KB |
testcase_13 | AC | 1,903 ms
77,584 KB |
testcase_14 | AC | 1,931 ms
77,692 KB |
testcase_15 | AC | 1,808 ms
78,132 KB |
testcase_16 | AC | 752 ms
76,836 KB |
testcase_17 | AC | 1,005 ms
77,116 KB |
testcase_18 | AC | 1,996 ms
77,572 KB |
testcase_19 | AC | 1,929 ms
78,272 KB |
testcase_20 | AC | 1,985 ms
77,820 KB |
testcase_21 | AC | 1,935 ms
77,600 KB |
testcase_22 | AC | 1,886 ms
77,440 KB |
testcase_23 | AC | 1,883 ms
77,688 KB |
testcase_24 | AC | 1,936 ms
80,488 KB |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | AC | 1,933 ms
79,416 KB |
testcase_28 | AC | 1,930 ms
77,696 KB |
testcase_29 | AC | 1,824 ms
77,244 KB |
testcase_30 | AC | 43 ms
52,480 KB |
testcase_31 | AC | 40 ms
52,472 KB |
testcase_32 | MLE | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
## https://yukicoder.me/problems/no/2204 B = 30 H = 9007199254740997 def main(): S = input() # 後ろからの累積で対応 hash_array = [0] * len(S) hs = 0 for i in reversed(range(len(S))): hs *= B hs %= H hs += ord(S[i]) - ord("a") + 1 hs %= H hash_array[i] = hs pow_b = [0] * (len(S) + 1) b = 1 for i in range(len(S) + 1): pow_b[i] = b b *= B b %= H parindrome_map = {(i, i): 1 for i in range(len(S))} for i in range(len(S)): hs = 0 for j in range(i, len(S)): hs *= B hs %= H hs += ord(S[j]) - ord("a") + 1 hs %= H # 偶数長 k = j - i j_ = j + 1 i_ = j_ + k if i_ < len(S): if i_ == len(S) - 1: h = hash_array[j_] else: h = (hash_array[j_] - (hash_array[i_ + 1] * pow_b[k + 1]) % H) % H if hs == h: parindrome_map[(i, i_)] = (k + 1) * 2 # 奇数長 k = j - i j_ = j + 2 i_ = j_ + k if i_ < len(S): if i_ == len(S) - 1: h = hash_array[j_] else: h = (hash_array[j_] - (hash_array[i_ + 1] * pow_b[k + 1]) % H) % H if hs == h: parindrome_map[(i, i_)] = (k + 1) * 2 + 1 def solve(S, parindrome_map, value): dp = [False for _ in range(len(S))] for i in range(len(S)): if (0, i) in parindrome_map and parindrome_map[(0, i)] >= value: dp[i] = True for j in range(i): if dp[j]: if (j + 1, i) in parindrome_map and parindrome_map[(j + 1, i)] >= value: dp[i] = True return dp[-1] low = 0 high = len(S) while high - low > 1: mid = (high + low ) // 2 if solve(S, parindrome_map, mid): low = mid else: high = mid if solve(S, parindrome_map, high): print(high) else: print(low) if __name__ == '__main__': main()