結果

問題 No.1845 Long Substrings
ユーザー ああいいああいい
提出日時 2022-02-18 23:02:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 628 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 87,096 KB
実行使用メモリ 109,964 KB
最終ジャッジ日時 2023-09-11 19:58:00
合計ジャッジ時間 5,611 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
105,224 KB
testcase_01 AC 122 ms
109,668 KB
testcase_02 AC 144 ms
105,260 KB
testcase_03 AC 144 ms
105,204 KB
testcase_04 AC 126 ms
109,964 KB
testcase_05 AC 137 ms
101,924 KB
testcase_06 AC 141 ms
104,776 KB
testcase_07 AC 123 ms
109,564 KB
testcase_08 AC 140 ms
104,492 KB
testcase_09 AC 140 ms
104,644 KB
testcase_10 AC 122 ms
109,584 KB
testcase_11 AC 136 ms
102,036 KB
testcase_12 AC 137 ms
102,748 KB
testcase_13 AC 122 ms
109,568 KB
testcase_14 AC 142 ms
104,900 KB
testcase_15 AC 84 ms
76,320 KB
testcase_16 AC 83 ms
76,328 KB
testcase_17 AC 83 ms
76,364 KB
testcase_18 AC 85 ms
76,652 KB
testcase_19 AC 84 ms
76,540 KB
testcase_20 AC 75 ms
71,412 KB
testcase_21 AC 74 ms
71,284 KB
testcase_22 AC 75 ms
71,324 KB
testcase_23 AC 76 ms
71,328 KB
testcase_24 AC 73 ms
71,148 KB
testcase_25 AC 75 ms
71,180 KB
testcase_26 AC 75 ms
71,316 KB
testcase_27 AC 74 ms
71,292 KB
testcase_28 AC 77 ms
71,024 KB
testcase_29 AC 75 ms
71,028 KB
testcase_30 AC 73 ms
71,220 KB
testcase_31 AC 74 ms
71,164 KB
testcase_32 AC 74 ms
71,296 KB
testcase_33 AC 74 ms
71,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
A = list(map(int,input().split()))
S = input()
last = [-1] * 26
P = 10 ** 9 + 7
dp = [0] * N
_sum = [0] * (N+1)
dp[0] = A[0]
c = ord(S[0]) - ord('a')
last[c] = 0
_sum[1] = A[0]
hoka = [0] * N
hoka[0] = 1
for i in range(1,N):
    c = ord(S[i]) - ord('a')
    if last[c] == -1:
        dp[i] = (_sum[i]+1) * A[i] % P
        hoka[i] = _sum[i]+1
    else:
        dp[i] = (_sum[i] - _sum[last[c]+1] + hoka[last[c]] ) * A[i] % P
        hoka[i] = (_sum[i] - _sum[last[c]+1] + hoka[last[c]]) % P
    _sum[i+1] = (_sum[i] + dp[i]) % P
    last[c] = i
ans = 0
for i in range(N):
    ans = (ans + dp[i]) % P
print(ans)
0