結果

問題 No.1845 Long Substrings
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-02-21 22:42:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 421 ms / 2,000 ms
コード長 664 bytes
コンパイル時間 546 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 147,668 KB
最終ジャッジ日時 2023-09-12 13:25:26
合計ジャッジ時間 11,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 404 ms
147,636 KB
testcase_01 AC 392 ms
137,836 KB
testcase_02 AC 421 ms
147,668 KB
testcase_03 AC 416 ms
147,456 KB
testcase_04 AC 400 ms
137,388 KB
testcase_05 AC 371 ms
140,124 KB
testcase_06 AC 399 ms
145,516 KB
testcase_07 AC 397 ms
137,580 KB
testcase_08 AC 399 ms
143,560 KB
testcase_09 AC 403 ms
145,124 KB
testcase_10 AC 386 ms
137,180 KB
testcase_11 AC 379 ms
140,276 KB
testcase_12 AC 391 ms
142,260 KB
testcase_13 AC 387 ms
135,896 KB
testcase_14 AC 405 ms
146,752 KB
testcase_15 AC 93 ms
76,876 KB
testcase_16 AC 93 ms
76,940 KB
testcase_17 AC 94 ms
76,968 KB
testcase_18 AC 92 ms
76,560 KB
testcase_19 AC 95 ms
76,952 KB
testcase_20 AC 75 ms
71,140 KB
testcase_21 AC 74 ms
71,284 KB
testcase_22 AC 74 ms
71,216 KB
testcase_23 AC 72 ms
71,264 KB
testcase_24 AC 74 ms
71,208 KB
testcase_25 AC 74 ms
71,068 KB
testcase_26 AC 74 ms
71,244 KB
testcase_27 AC 73 ms
71,348 KB
testcase_28 AC 74 ms
71,148 KB
testcase_29 AC 74 ms
71,584 KB
testcase_30 AC 74 ms
71,144 KB
testcase_31 AC 74 ms
71,576 KB
testcase_32 AC 73 ms
71,528 KB
testcase_33 AC 74 ms
71,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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