結果
問題 |
No.1171 Runs in Subsequences
|
ユーザー |
|
提出日時 | 2022-02-23 13:18:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 55 ms / 2,000 ms |
コード長 | 524 bytes |
コンパイル時間 | 217 ms |
コンパイル使用メモリ | 82,112 KB |
実行使用メモリ | 64,128 KB |
最終ジャッジ日時 | 2024-07-01 13:09:28 |
合計ジャッジ時間 | 2,345 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 18 |
ソースコード
S = input() N = len(S) P = 10 ** 9 + 7 ans = 0 _sum = 0 Sum = [0] * 26 dp = [0] * N _tum = 0 Tum = [0] * 26 dpc = [0] * N dp[0] = 1 _sum = 1 c = ord(S[0]) - ord('a') Sum[c] = 1 Tum[c] = 1 _tum = 1 dpc[0] = 1 for i in range(N-1): c = ord(S[i+1]) - ord('a') tmp = _sum - Sum[c] + _tum - Tum[c] + 1 tmp %= P tmp += Sum[c] tmp %= P ans = (ans + tmp) % P _sum = (_sum + tmp) % P Sum[c] = (Sum[c] + tmp) % P Tum[c] = (Tum[c] + _tum + 1) % P _tum = (_tum + 1) * 2 % P - 1 print((ans+1) % P)