結果

問題 No.1845 Long Substrings
ユーザー ああいいああいい
提出日時 2022-02-18 22:43:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 490 bytes
コンパイル時間 421 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 108,388 KB
最終ジャッジ日時 2023-09-11 19:44:24
合計ジャッジ時間 5,715 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 74 ms
71,404 KB
testcase_22 AC 74 ms
71,200 KB
testcase_23 AC 74 ms
71,000 KB
testcase_24 AC 73 ms
71,192 KB
testcase_25 AC 73 ms
71,260 KB
testcase_26 AC 74 ms
71,356 KB
testcase_27 AC 74 ms
71,000 KB
testcase_28 AC 73 ms
71,404 KB
testcase_29 AC 73 ms
71,220 KB
testcase_30 AC 73 ms
71,212 KB
testcase_31 AC 74 ms
71,268 KB
testcase_32 AC 74 ms
71,192 KB
testcase_33 AC 73 ms
71,268 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]
for i in range(1,N):
    c = ord(S[i]) - ord('a')
    if last[c] == -1:
        dp[i] = (_sum[i]+1) * A[i] % P
    else:
        dp[i] = (_sum[i] - dp[last[c]] + 1) * A[i] % 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