結果

問題 No.1845 Long Substrings
ユーザー rlangevinrlangevin
提出日時 2023-02-05 17:03:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 491 bytes
コンパイル時間 377 ms
コンパイル使用メモリ 87,276 KB
実行使用メモリ 117,728 KB
最終ジャッジ日時 2023-09-17 08:43:41
合計ジャッジ時間 7,137 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
117,688 KB
testcase_01 AC 183 ms
110,020 KB
testcase_02 AC 199 ms
117,728 KB
testcase_03 AC 200 ms
117,728 KB
testcase_04 AC 185 ms
109,820 KB
testcase_05 AC 187 ms
113,124 KB
testcase_06 AC 197 ms
117,404 KB
testcase_07 AC 184 ms
109,724 KB
testcase_08 AC 195 ms
117,088 KB
testcase_09 AC 196 ms
117,212 KB
testcase_10 AC 184 ms
110,204 KB
testcase_11 AC 184 ms
113,088 KB
testcase_12 AC 187 ms
113,796 KB
testcase_13 AC 180 ms
109,864 KB
testcase_14 AC 196 ms
117,660 KB
testcase_15 AC 85 ms
76,956 KB
testcase_16 AC 81 ms
77,080 KB
testcase_17 AC 80 ms
76,968 KB
testcase_18 AC 81 ms
77,052 KB
testcase_19 AC 83 ms
76,856 KB
testcase_20 AC 69 ms
71,360 KB
testcase_21 AC 70 ms
71,688 KB
testcase_22 AC 71 ms
71,516 KB
testcase_23 AC 72 ms
71,528 KB
testcase_24 AC 70 ms
71,520 KB
testcase_25 AC 72 ms
71,472 KB
testcase_26 AC 73 ms
71,304 KB
testcase_27 AC 72 ms
71,364 KB
testcase_28 AC 70 ms
71,304 KB
testcase_29 AC 69 ms
71,624 KB
testcase_30 AC 71 ms
71,192 KB
testcase_31 AC 71 ms
71,328 KB
testcase_32 AC 74 ms
71,672 KB
testcase_33 AC 71 ms
71,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def alp_to_num(cha):
    num = ord(cha) - ord("a")
    return num

N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7
S = list(input())
S = list(map(alp_to_num, S))

pre = [0] * 27
pre[26] = 1
psm = 1
for i in range(N):
    dp = [0] * 27
    sm = 0
    dp[S[i]] += (psm - pre[S[i]]) * A[i]
    for c in range(27):
        dp[c] += pre[c]
        sm += dp[c]
        dp[c] %= mod
        sm %= mod
    dp, pre = pre, dp
    sm, psm = psm, sm 
print(sum(pre[:26])% mod)    
0