結果

問題 No.1845 Long Substrings
ユーザー 👑 potato167potato167
提出日時 2021-12-07 03:49:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 318 bytes
コンパイル時間 963 ms
コンパイル使用メモリ 86,776 KB
実行使用メモリ 108,264 KB
最終ジャッジ日時 2023-10-14 23:13:48
合計ジャッジ時間 6,240 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
103,828 KB
testcase_01 AC 115 ms
108,224 KB
testcase_02 AC 140 ms
103,844 KB
testcase_03 AC 139 ms
103,868 KB
testcase_04 AC 114 ms
108,104 KB
testcase_05 AC 137 ms
100,944 KB
testcase_06 AC 141 ms
103,528 KB
testcase_07 AC 114 ms
108,060 KB
testcase_08 AC 136 ms
103,172 KB
testcase_09 AC 140 ms
103,256 KB
testcase_10 AC 113 ms
108,264 KB
testcase_11 AC 133 ms
100,608 KB
testcase_12 AC 132 ms
101,360 KB
testcase_13 AC 113 ms
107,988 KB
testcase_14 AC 139 ms
103,556 KB
testcase_15 AC 80 ms
76,456 KB
testcase_16 AC 79 ms
76,460 KB
testcase_17 AC 80 ms
76,416 KB
testcase_18 AC 79 ms
76,348 KB
testcase_19 AC 80 ms
76,744 KB
testcase_20 AC 71 ms
71,020 KB
testcase_21 AC 71 ms
71,112 KB
testcase_22 AC 71 ms
71,000 KB
testcase_23 AC 71 ms
71,212 KB
testcase_24 AC 70 ms
71,412 KB
testcase_25 AC 71 ms
71,256 KB
testcase_26 AC 71 ms
70,988 KB
testcase_27 AC 69 ms
71,404 KB
testcase_28 AC 71 ms
71,392 KB
testcase_29 AC 71 ms
71,248 KB
testcase_30 AC 71 ms
71,252 KB
testcase_31 AC 71 ms
71,000 KB
testcase_32 AC 70 ms
71,424 KB
testcase_33 AC 69 ms
71,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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])
0