結果
問題 | No.1845 Long Substrings |
ユーザー |
![]() |
提出日時 | 2022-02-18 22:45:09 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 253 ms / 2,000 ms |
コード長 | 620 bytes |
コンパイル時間 | 198 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 115,780 KB |
最終ジャッジ日時 | 2024-06-29 09:32:01 |
合計ジャッジ時間 | 5,961 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
mod = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) S = [ord(s) - 97 for s in input()] pos = [[] for _ in range(26)] for i in reversed(range(N)): pos[S[i]].append(i) dp = [0] * N for i in range(26): if pos[i]: dp[pos[i][-1]] = 1 for i, s in enumerate(S): pos[s].pop() for j in range(26): if pos[j] and s != j: dp[pos[j][-1]] += dp[i] * A[i] dp[pos[j][-1]] %= mod if pos[j] and s == j: dp[pos[j][-1]] += dp[i] dp[pos[j][-1]] %= mod ans = 0 for i in range(N): ans += A[i] * dp[i] ans %= mod print(ans)