結果

問題 No.1845 Long Substrings
ユーザー roarisroaris
提出日時 2022-06-17 23:29:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 362 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 82,068 KB
実行使用メモリ 115,840 KB
最終ジャッジ日時 2024-04-17 15:58:07
合計ジャッジ時間 5,088 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 134 ms
114,304 KB
testcase_01 AC 111 ms
115,840 KB
testcase_02 AC 128 ms
114,684 KB
testcase_03 AC 127 ms
114,312 KB
testcase_04 AC 107 ms
115,584 KB
testcase_05 AC 112 ms
103,424 KB
testcase_06 AC 119 ms
105,344 KB
testcase_07 AC 110 ms
114,944 KB
testcase_08 AC 117 ms
105,728 KB
testcase_09 AC 118 ms
105,728 KB
testcase_10 AC 107 ms
115,072 KB
testcase_11 AC 110 ms
104,088 KB
testcase_12 AC 114 ms
102,272 KB
testcase_13 AC 107 ms
115,072 KB
testcase_14 AC 128 ms
114,816 KB
testcase_15 AC 54 ms
61,440 KB
testcase_16 AC 54 ms
61,056 KB
testcase_17 AC 54 ms
61,440 KB
testcase_18 AC 55 ms
61,056 KB
testcase_19 AC 54 ms
61,312 KB
testcase_20 AC 46 ms
51,968 KB
testcase_21 AC 46 ms
51,712 KB
testcase_22 AC 44 ms
51,584 KB
testcase_23 AC 45 ms
52,096 KB
testcase_24 AC 44 ms
51,840 KB
testcase_25 AC 44 ms
51,840 KB
testcase_26 AC 44 ms
51,712 KB
testcase_27 AC 44 ms
52,224 KB
testcase_28 AC 44 ms
51,840 KB
testcase_29 AC 46 ms
52,224 KB
testcase_30 AC 43 ms
51,584 KB
testcase_31 AC 45 ms
51,456 KB
testcase_32 AC 44 ms
51,712 KB
testcase_33 AC 45 ms
52,096 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
S = input()[:-1]
dp = [0]*(N+1)
dp[0] = 1
prev = [-1]*26
acc = [0]
MOD = 10**9+7

for i in range(N):
    j = prev[ord(S[i])-ord('a')]
    dp[i+1] = (acc[-1]-acc[j+1]+dp[j+1])%MOD
    acc.append((acc[-1]+dp[i+1]*A[i])%MOD)
    prev[ord(S[i])-ord('a')] = i

print(acc[-1])
0