結果

問題 No.238 Mr. K's Another Gift
ユーザー rlangevinrlangevin
提出日時 2024-01-25 12:35:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,115 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 119,152 KB
最終ジャッジ日時 2024-01-25 12:35:56
合計ジャッジ時間 5,218 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,332 KB
testcase_01 AC 36 ms
53,332 KB
testcase_02 AC 38 ms
53,332 KB
testcase_03 AC 81 ms
76,068 KB
testcase_04 AC 234 ms
79,172 KB
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

class RollingHash():
    def __init__(self, s):
        self._mod = 2 ** 64 - 1
        self._base = 4649
        
        n = len(s)
        self.h = [0] * (n + 1)
        self.pw = [1] * (n + 5)
 
        for i in range(n):
            self.h[i + 1] = self.h[i] * self._base + ord(s[i])
            self.h[i + 1] %= self._mod
 
        for i in range(n + 4):
            self.pw[i + 1] = self.pw[i] * self._base
            self.pw[i + 1] %= self._mod
            
        """
        s[l:r]のhash値
        """
    def get(self, l, r):
        return (self.h[r] - self.h[l] * self.pw[r - l]) % self._mod
    
S1 = list(input())
S2 = S1[::-1]
R1 = RollingHash(S1)
R2 = RollingHash(S2)
N = len(S1)
pw = R1.pw
mod = R1._mod
for i in range(N + 1):
    for s in range(26):
        si = s + ord("a")
        v1 = (R1.get(0, i) * pw[N - i + 1] + R1.get(i, N) + si * pw[N - i]) % mod
        v2 = (R2.get(0, N - i) * pw[i + 1] + R2.get(N - i, N) + si * pw[i]) % mod
        if v1 == v2:
            ans = S1[:i] + [chr(ord("a") + s)] + S1[i:]
            print(*ans, sep="")
            exit()
            
print("NA")
0