結果

問題 No.1845 Long Substrings
ユーザー tktk_snsntktk_snsn
提出日時 2022-02-18 22:45:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 1,544 ms
コンパイル使用メモリ 86,820 KB
実行使用メモリ 115,740 KB
最終ジャッジ日時 2023-09-11 19:46:37
合計ジャッジ時間 7,650 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 223 ms
115,740 KB
testcase_01 AC 236 ms
105,356 KB
testcase_02 AC 274 ms
103,312 KB
testcase_03 AC 271 ms
103,400 KB
testcase_04 AC 267 ms
105,392 KB
testcase_05 AC 206 ms
111,812 KB
testcase_06 AC 235 ms
103,216 KB
testcase_07 AC 261 ms
105,360 KB
testcase_08 AC 266 ms
102,948 KB
testcase_09 AC 268 ms
103,140 KB
testcase_10 AC 203 ms
105,396 KB
testcase_11 AC 239 ms
100,680 KB
testcase_12 AC 262 ms
101,144 KB
testcase_13 AC 248 ms
105,396 KB
testcase_14 AC 276 ms
103,496 KB
testcase_15 AC 88 ms
76,344 KB
testcase_16 AC 87 ms
76,320 KB
testcase_17 AC 90 ms
76,700 KB
testcase_18 AC 89 ms
76,768 KB
testcase_19 AC 91 ms
76,676 KB
testcase_20 AC 71 ms
71,224 KB
testcase_21 AC 71 ms
71,160 KB
testcase_22 AC 70 ms
71,148 KB
testcase_23 AC 71 ms
71,268 KB
testcase_24 AC 76 ms
71,248 KB
testcase_25 AC 69 ms
71,164 KB
testcase_26 AC 71 ms
71,176 KB
testcase_27 AC 69 ms
71,032 KB
testcase_28 AC 69 ms
71,184 KB
testcase_29 AC 70 ms
71,036 KB
testcase_30 AC 71 ms
71,152 KB
testcase_31 AC 70 ms
71,208 KB
testcase_32 AC 71 ms
71,132 KB
testcase_33 AC 69 ms
71,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 10 ** 9 + 7


N = int(input())
A = list(map(int, input().split()))
S = [ord(s) - 97 for s in input()]
pos = [[] for _ in range(26)]
for i in reversed(range(N)):
    pos[S[i]].append(i)

dp = [0] * N
for i in range(26):
    if pos[i]:
        dp[pos[i][-1]] = 1

for i, s in enumerate(S):
    pos[s].pop()
    for j in range(26):
        if pos[j] and s != j:
            dp[pos[j][-1]] += dp[i] * A[i]
            dp[pos[j][-1]] %= mod
        if pos[j] and s == j:
            dp[pos[j][-1]] += dp[i]
            dp[pos[j][-1]] %= mod


ans = 0
for i in range(N):
    ans += A[i] * dp[i]
    ans %= mod
print(ans)
0