結果
| 問題 | 
                            No.1845 Long Substrings
                             | 
                    
| コンテスト | |
| ユーザー | 
                            👑  potato167
                         | 
                    
| 提出日時 | 2021-12-07 03:49:37 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 115 ms / 2,000 ms | 
| コード長 | 318 bytes | 
| コンパイル時間 | 285 ms | 
| コンパイル使用メモリ | 82,560 KB | 
| 実行使用メモリ | 107,648 KB | 
| 最終ジャッジ日時 | 2024-09-16 16:46:02 | 
| 合計ジャッジ時間 | 4,236 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge6 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 34 | 
ソースコード
N=int(input())
A=list(map(int,input().split()))
S=input()
M=10**9+7
p=[0]*26
dp=[0]*N
sum=[0]*(N+1)
ans=0
for i in range(N):
	c=ord(S[i])-ord('a')
	tmp=p[c]
	p[c]=i+1
	dp[i]=sum[i]
	if tmp==0:
		dp[i]+=1
	else:
		dp[i]-=sum[tmp]
		dp[i]+=dp[tmp-1]
	sum[i+1]=(A[i]*dp[i])%M
	sum[i+1]+=sum[i]
	sum[i+1]%=M
print(sum[N])
            
            
            
        
            
potato167