結果
| 問題 | No.1845 Long Substrings |
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2021-12-07 03:49:37 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 80 ms / 2,000 ms |
| コード長 | 318 bytes |
| 記録 | |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 116,992 KB |
| 最終ジャッジ日時 | 2026-04-05 21:28:25 |
| 合計ジャッジ時間 | 2,835 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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