結果
| 問題 |
No.1845 Long Substrings
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-02-21 22:42:11 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 363 ms / 2,000 ms |
| コード長 | 664 bytes |
| コンパイル時間 | 159 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 145,744 KB |
| 最終ジャッジ日時 | 2024-06-30 01:41:17 |
| 合計ジャッジ時間 | 8,311 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 34 |
ソースコード
n = int(input())
A = list(map(int,input().split()))
S = input()
mod = 10**9+7
next = [[n]*26 for i in range(n+1)]
for i in range(n)[::-1]:
s = ord(S[i])-ord("a")
for j in range(26):
if j == s:
next[i][j] = i
else:
next[i][j] = next[i+1][j]
dp = [0]*(n+2)
for i in range(26):
if next[0][i] != n:
dp[next[0][i]] += 1
ans = 0
for i,(a,s) in enumerate(zip(A,S)):
s = ord(s)-ord("a")
ans += dp[i]*a
ans %= mod
for j in range(26):
if s == j:
dp[next[i+1][j]] += dp[i]
else:
dp[next[i+1][j]] += dp[i]*a%mod
dp[next[i+1][j]] %= mod
print(ans)