結果

問題 No.1845 Long Substrings
ユーザー square1001square1001
提出日時 2022-02-18 21:43:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 278 ms / 2,000 ms
コード長 293 bytes
コンパイル時間 243 ms
コンパイル使用メモリ 10,456 KB
実行使用メモリ 30,444 KB
最終ジャッジ日時 2023-09-11 18:48:06
合計ジャッジ時間 6,409 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
30,316 KB
testcase_01 AC 242 ms
17,832 KB
testcase_02 AC 277 ms
30,436 KB
testcase_03 AC 278 ms
30,444 KB
testcase_04 AC 248 ms
17,564 KB
testcase_05 AC 264 ms
28,140 KB
testcase_06 AC 268 ms
29,600 KB
testcase_07 AC 265 ms
17,744 KB
testcase_08 AC 258 ms
28,884 KB
testcase_09 AC 259 ms
29,560 KB
testcase_10 AC 249 ms
17,956 KB
testcase_11 AC 253 ms
28,144 KB
testcase_12 AC 257 ms
28,748 KB
testcase_13 AC 242 ms
17,556 KB
testcase_14 AC 275 ms
30,136 KB
testcase_15 AC 19 ms
8,424 KB
testcase_16 AC 20 ms
8,228 KB
testcase_17 AC 20 ms
8,512 KB
testcase_18 AC 19 ms
8,164 KB
testcase_19 AC 21 ms
8,328 KB
testcase_20 AC 15 ms
7,700 KB
testcase_21 AC 16 ms
7,840 KB
testcase_22 AC 15 ms
7,836 KB
testcase_23 AC 15 ms
7,804 KB
testcase_24 AC 16 ms
7,760 KB
testcase_25 AC 16 ms
7,756 KB
testcase_26 AC 15 ms
7,776 KB
testcase_27 AC 15 ms
7,704 KB
testcase_28 AC 15 ms
7,864 KB
testcase_29 AC 16 ms
7,880 KB
testcase_30 AC 16 ms
7,728 KB
testcase_31 AC 16 ms
7,848 KB
testcase_32 AC 15 ms
7,796 KB
testcase_33 AC 15 ms
7,760 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 1000000007

N = int(input())
A = list(map(int, input().split()))
S = input()

dp = [ 0 ] * N
dpsum = [ 0 ] * 26
dpallsum = 0
for i in range(0, N):
	ch = ord(S[i]) - ord('a')
	dp[i] = ((1 + (dpallsum - dpsum[ch])) * A[i]) % MOD
	dpsum[ch] += dp[i]
	dpallsum += dp[i]

print(sum(dp) % MOD)
0