結果
問題 | No.1845 Long Substrings |
ユーザー |
![]() |
提出日時 | 2023-10-30 18:54:14 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 368 ms / 2,000 ms |
コード長 | 1,322 bytes |
コンパイル時間 | 864 ms |
コンパイル使用メモリ | 82,468 KB |
実行使用メモリ | 191,960 KB |
最終ジャッジ日時 | 2024-09-25 17:20:34 |
合計ジャッジ時間 | 8,383 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import sys# sys.setrecursionlimit(1000005)# sys.set_int_max_str_digits(200005)int1 = lambda x: int(x)-1pDB = lambda *x: print(*x, end="\n", file=sys.stderr)p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)def II(): return int(sys.stdin.readline())def LI(): return list(map(int, sys.stdin.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LI1(): return list(map(int1, sys.stdin.readline().split()))def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def SI(): return sys.stdin.readline().rstrip()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]# inf = -1-(-1 << 31)inf = -1-(-1 << 63)md = 10**9+7# md = 998244353n = II()aa = LI()cc = [ord(c)-97 for c in SI()]nxt = [[-1]*26 for _ in range(n)]for i in range(n-1)[::-1]:nxt[i] = nxt[i+1][:]nxt[i][cc[i+1]] = i+1# p2D(nxt)ans = 0dp = [0]*nfirst = [1]*26for i, c in enumerate(cc):pre = dp[i]if first[c]:pre += 1first[c] = 0ans += pre*aa[i]%mdans %= mdfor nc in range(26):if nxt[i][nc] == -1: continuej = nxt[i][nc]if c == nc:dp[j] += preelse:dp[j] += pre*aa[i]%mddp[j] %= mdprint(ans)