結果

問題 No.1845 Long Substrings
ユーザー lilictakalilictaka
提出日時 2022-05-09 17:42:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,236 ms / 2,000 ms
コード長 775 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 87,000 KB
実行使用メモリ 131,028 KB
最終ジャッジ日時 2023-09-23 16:02:13
合計ジャッジ時間 19,613 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 359 ms
131,028 KB
testcase_01 AC 776 ms
109,424 KB
testcase_02 AC 973 ms
120,328 KB
testcase_03 AC 1,236 ms
120,292 KB
testcase_04 AC 1,225 ms
109,208 KB
testcase_05 AC 329 ms
124,908 KB
testcase_06 AC 690 ms
120,296 KB
testcase_07 AC 1,100 ms
109,332 KB
testcase_08 AC 1,201 ms
120,100 KB
testcase_09 AC 1,224 ms
120,320 KB
testcase_10 AC 336 ms
115,508 KB
testcase_11 AC 795 ms
116,000 KB
testcase_12 AC 1,144 ms
116,472 KB
testcase_13 AC 1,106 ms
109,380 KB
testcase_14 AC 1,217 ms
120,324 KB
testcase_15 AC 111 ms
78,072 KB
testcase_16 AC 111 ms
77,580 KB
testcase_17 AC 119 ms
77,960 KB
testcase_18 AC 119 ms
77,636 KB
testcase_19 AC 131 ms
77,940 KB
testcase_20 AC 77 ms
71,608 KB
testcase_21 AC 75 ms
71,224 KB
testcase_22 AC 76 ms
71,460 KB
testcase_23 AC 77 ms
71,192 KB
testcase_24 AC 75 ms
71,356 KB
testcase_25 AC 77 ms
71,048 KB
testcase_26 AC 76 ms
71,352 KB
testcase_27 AC 75 ms
71,196 KB
testcase_28 AC 75 ms
71,272 KB
testcase_29 AC 77 ms
71,404 KB
testcase_30 AC 78 ms
71,464 KB
testcase_31 AC 78 ms
71,484 KB
testcase_32 AC 77 ms
71,468 KB
testcase_33 AC 78 ms
71,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left
def ch(s):
    return ord(s) - ord('a')
N = int(input())
memo = [[] for _ in range(26)]
A = list(map(int,input().split()))
mod = 10 ** 9 + 7
S = list(map(ch,list(input())))
dp = [0 for _ in range(N)]
for i in range(N):
    if memo[S[i]] == []:
        dp[i] = 1
    memo[S[i]].append(i)
for i in range(N):
    for k in range(26):
        if memo[k] == []:
            pass
        else:
            index = bisect_left(memo[k],i+1)
            if index == len(memo[k]):
                continue
            nx = memo[k][index]
            if S[i] == k:
                dp[nx] += dp[i]
            else:
                dp[nx] += dp[i] * A[i]
            dp[nx] %= mod
ans = 0
for i in range(N):
    ans += dp[i] * A[i]
    ans %= mod
print(ans)
0