結果
問題 |
No.2905 Nabeatsu Integration
|
ユーザー |
|
提出日時 | 2024-08-21 23:32:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 146 ms / 2,000 ms |
コード長 | 810 bytes |
コンパイル時間 | 271 ms |
コンパイル使用メモリ | 82,836 KB |
実行使用メモリ | 95,020 KB |
最終ジャッジ日時 | 2024-09-07 11:34:02 |
合計ジャッジ時間 | 10,177 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 70 |
ソースコード
import typing def z_algorithm(s: typing.Union[str, typing.List[int]]) -> typing.List[int]: ''' Z algorithm Reference: D. Gusfield, Algorithms on Strings, Trees, and Sequences: Computer Science and Computational Biology ''' if isinstance(s, str): s = [ord(c) for c in s] n = len(s) if n == 0: return [] z = [0] * n j = 0 for i in range(1, n): z[i] = 0 if j + z[j] <= i else min(j + z[j] - i, z[i - j]) while i + z[i] < n and s[z[i]] == s[i + z[i]]: z[i] += 1 if j + z[j] < i + z[i]: j = i z[0] = n return z MOD=998244353 s=input() n=len(s) z=z_algorithm(s) ans=MOD-n+1 p=10 for i in range(1,n+1): if z[n-i]==i: ans+=p ans%=MOD p*=10 p%=MOD print(ans)