結果
問題 | No.2858 Make a Palindrome |
ユーザー | tassei903 |
提出日時 | 2024-08-25 15:59:40 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 413 ms / 3,000 ms |
コード長 | 1,819 bytes |
コンパイル時間 | 163 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 99,576 KB |
最終ジャッジ日時 | 2024-08-25 15:59:51 |
合計ジャッジ時間 | 10,218 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 413 ms
81,084 KB |
testcase_01 | AC | 287 ms
79,680 KB |
testcase_02 | AC | 261 ms
79,604 KB |
testcase_03 | AC | 284 ms
78,888 KB |
testcase_04 | AC | 261 ms
79,616 KB |
testcase_05 | AC | 252 ms
79,376 KB |
testcase_06 | AC | 246 ms
78,500 KB |
testcase_07 | AC | 259 ms
78,012 KB |
testcase_08 | AC | 249 ms
78,892 KB |
testcase_09 | AC | 256 ms
78,264 KB |
testcase_10 | AC | 254 ms
77,748 KB |
testcase_11 | AC | 227 ms
77,624 KB |
testcase_12 | AC | 230 ms
77,932 KB |
testcase_13 | AC | 236 ms
77,504 KB |
testcase_14 | AC | 260 ms
77,904 KB |
testcase_15 | AC | 207 ms
77,104 KB |
testcase_16 | AC | 161 ms
78,116 KB |
testcase_17 | AC | 187 ms
77,556 KB |
testcase_18 | AC | 215 ms
77,672 KB |
testcase_19 | AC | 222 ms
77,716 KB |
testcase_20 | AC | 168 ms
96,420 KB |
testcase_21 | AC | 169 ms
96,652 KB |
testcase_22 | AC | 108 ms
86,640 KB |
testcase_23 | AC | 143 ms
96,280 KB |
testcase_24 | AC | 135 ms
93,748 KB |
testcase_25 | AC | 133 ms
91,432 KB |
testcase_26 | AC | 130 ms
91,008 KB |
testcase_27 | AC | 168 ms
98,740 KB |
testcase_28 | AC | 174 ms
92,756 KB |
testcase_29 | AC | 167 ms
96,924 KB |
testcase_30 | AC | 173 ms
99,564 KB |
testcase_31 | AC | 188 ms
98,992 KB |
testcase_32 | AC | 174 ms
99,020 KB |
testcase_33 | AC | 172 ms
99,384 KB |
testcase_34 | AC | 175 ms
99,576 KB |
testcase_35 | AC | 181 ms
99,396 KB |
testcase_36 | AC | 150 ms
99,460 KB |
testcase_37 | AC | 145 ms
99,488 KB |
testcase_38 | AC | 168 ms
99,496 KB |
testcase_39 | AC | 168 ms
99,220 KB |
ソースコード
import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### def manacher(s): s = s.replace('', '#') n = len(s) p = [1 for _ in range(n)] c = 0 for i in range(1, n): if i < c + p[c]: p[i] = min(p[c - (i - c)], c + p[c] - i) while i - p[i] >= 0 and i + p[i] < n and s[i - p[i]] == s[i + p[i]]: p[i] += 1 if i + p[i] > c + p[c]: c = i return p def max_palindrome(s): P = manacher(s) return max(P) - 1 def solve(n, m, s): A = max_palindrome(s) B = max_palindrome(s + s) C = max_palindrome(s + s + s) if A >= m: return 1 elif B >= m: return 2 elif C >= m: return 3 elif B == C and B < m: return -1 else: return 3 + (m - B - 1) // (C - B) def greedy(n, m, s): z = "" for t in range(1000): if max_palindrome(z) >= m: return t z += s return -1 for _ in range(ni()): n, m = na() s = input() print(solve(n, m, s)) #print(greedy(n, m, s)) # from random import randint # for _ in range(10000): # n = randint(1, 10) # m = randint(1, n * 10) # s = "".join([chr(randint(97, 122)) for _ in range(n)]) # if solve(n, m, s) != greedy(n, m, s): # print(n, m) # print(s) # print(solve(n, m, s)) # print(greedy(n, m, s)) # break # #print(_) # n, m = na() # s = input() # print(solve(n, m, s)) # z = s # for i in range(4): # print(*manacher(z)) # z += s