結果

問題 No.1845 Long Substrings
ユーザー ygd.ygd.
提出日時 2022-02-18 22:35:37
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 201 ms / 2,000 ms
コード長 1,211 bytes
コンパイル時間 357 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 114,548 KB
最終ジャッジ日時 2023-09-11 19:36:52
合計ジャッジ時間 7,049 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 194 ms
109,876 KB
testcase_01 AC 185 ms
104,676 KB
testcase_02 AC 195 ms
109,616 KB
testcase_03 AC 193 ms
107,636 KB
testcase_04 AC 188 ms
104,260 KB
testcase_05 AC 193 ms
110,584 KB
testcase_06 AC 199 ms
114,380 KB
testcase_07 AC 190 ms
104,380 KB
testcase_08 AC 199 ms
114,208 KB
testcase_09 AC 200 ms
114,236 KB
testcase_10 AC 185 ms
104,160 KB
testcase_11 AC 192 ms
110,524 KB
testcase_12 AC 195 ms
110,744 KB
testcase_13 AC 183 ms
104,168 KB
testcase_14 AC 201 ms
114,548 KB
testcase_15 AC 100 ms
77,048 KB
testcase_16 AC 99 ms
76,700 KB
testcase_17 AC 99 ms
76,492 KB
testcase_18 AC 99 ms
76,752 KB
testcase_19 AC 102 ms
77,568 KB
testcase_20 AC 91 ms
71,576 KB
testcase_21 AC 88 ms
71,576 KB
testcase_22 AC 90 ms
71,572 KB
testcase_23 AC 88 ms
71,308 KB
testcase_24 AC 90 ms
71,556 KB
testcase_25 AC 89 ms
71,640 KB
testcase_26 AC 89 ms
71,616 KB
testcase_27 AC 90 ms
71,672 KB
testcase_28 AC 89 ms
71,572 KB
testcase_29 AC 90 ms
71,464 KB
testcase_30 AC 90 ms
71,716 KB
testcase_31 AC 90 ms
71,528 KB
testcase_32 AC 91 ms
71,712 KB
testcase_33 AC 91 ms
71,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline #文字列につけてはダメ
#input = sys.stdin.buffer.readline #文字列につけてはダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]


def main():
    N = int(input())
    A = list(map(int,input().split()))
    S = str(input())
    
    #dp[i][j]:i番目Aまで見て、アルファベットjが最後の時の場合の数。
    #j == 0は空文字列
    dp = [0]*27
    #dp[0] = 1
    for i in range(N):
        p = copy.copy(dp) #追加しないとき
        dp,p = p,dp
        v = A[i]
        s = ord(S[i]) - ord('a') + 1
        for j in range(27):
            #追加するとき
            if j == s: #同じ時はv個だけ最大が伸びる
                dp[s] += v
            else:
                dp[s] += p[j] * v
            dp[s] %= MOD
        #print(dp)
    ans = sum(dp)%MOD
    print(ans)



if __name__ == '__main__':
    main()
0