結果
問題 | No.238 Mr. K's Another Gift |
ユーザー |
![]() |
提出日時 | 2024-01-25 12:38:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,115 bytes |
コンパイル時間 | 247 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 128,432 KB |
最終ジャッジ日時 | 2024-09-28 07:20:10 |
合計ジャッジ時間 | 8,322 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 16 WA * 6 TLE * 18 |
ソースコード
class RollingHash():def __init__(self, s):self._mod = 2 ** 64 - 1self._base = 4649n = 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._modfor i in range(n + 4):self.pw[i + 1] = self.pw[i] * self._baseself.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._modS1 = list(input())S2 = S1[::-1]R1 = RollingHash(S1)R2 = RollingHash(S2)N = len(S1)pw = R1.pwmod = R1._modfor 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]) & modv2 = (R2.get(0, N - i) * pw[i + 1] + R2.get(N - i, N) + si * pw[i]) & modif v1 == v2:ans = S1[:i] + [chr(ord("a") + s)] + S1[i:]print(*ans, sep="")exit()print("NA")