結果
問題 | No.1845 Long Substrings |
ユーザー |
![]() |
提出日時 | 2023-02-05 17:03:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 179 ms / 2,000 ms |
コード長 | 491 bytes |
コンパイル時間 | 157 ms |
コンパイル使用メモリ | 82,316 KB |
実行使用メモリ | 117,024 KB |
最終ジャッジ日時 | 2024-07-04 05:20:17 |
合計ジャッジ時間 | 5,820 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
def alp_to_num(cha): num = ord(cha) - ord("a") return num N = int(input()) A = list(map(int, input().split())) mod = 10 ** 9 + 7 S = list(input()) S = list(map(alp_to_num, S)) pre = [0] * 27 pre[26] = 1 psm = 1 for i in range(N): dp = [0] * 27 sm = 0 dp[S[i]] += (psm - pre[S[i]]) * A[i] for c in range(27): dp[c] += pre[c] sm += dp[c] dp[c] %= mod sm %= mod dp, pre = pre, dp sm, psm = psm, sm print(sum(pre[:26])% mod)