結果
問題 |
No.1845 Long Substrings
|
ユーザー |
|
提出日時 | 2022-02-18 22:43:55 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 490 bytes |
コンパイル時間 | 218 ms |
コンパイル使用メモリ | 82,040 KB |
実行使用メモリ | 107,556 KB |
最終ジャッジ日時 | 2024-06-29 09:29:49 |
合計ジャッジ時間 | 3,905 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 13 WA * 21 |
ソースコード
N = int(input()) A = list(map(int,input().split())) S = input() last = [-1] * 26 P = 10 ** 9 + 7 dp = [0] * N _sum = [0] * (N+1) dp[0] = A[0] c = ord(S[0]) - ord('a') last[c] = 0 _sum[1] = A[0] for i in range(1,N): c = ord(S[i]) - ord('a') if last[c] == -1: dp[i] = (_sum[i]+1) * A[i] % P else: dp[i] = (_sum[i] - dp[last[c]] + 1) * A[i] % P _sum[i+1] = (_sum[i] + dp[i]) % P last[c] = i ans = 0 for i in range(N): ans = (ans + dp[i]) % P print(ans)